由于在comfyui便携版环境安装pynini相当困难(有人说解决了,但没有文章分享),至今未解决,从而导致无法安装ComfyUI_NTCosyVoice节点来实现文本转语音,但使用anaconda安装pynini则十分简单,从而想尝试用Miniconda安装comfyui,并进而安装ComfyUI_NTCosyVoice节点来实现文本转语音。
一、安装 Miniconda
点击官网下载 Miniconda,安装。
附注:
1、安装 Miniconda 时,会默认包含一个基础环境(base),其 Python 版本由你选择的 Miniconda 安装包决定(例如 Miniconda3-py38 对应 Python 3.8)。作用:
基础环境的 Python 主要用于运行 conda 包管理工具,不影响其他独立环境。2、频道与软件包可用性:
如果默认频道(defaults)中没有目标 Python 版本,需添加 conda-forge 频道:
conda create -n my_env -c conda-forge python=3.11
3、《Miniconda的常用命令》
二、配置 ComfyUI 专属环境
创建新环境并指定 Python 版本,然后激活环境: (conda为安装路径中的文件夹condabin里面的conda.bat ,而不是安装路径下的 _conda.exe)
G:\miniconda311\condabin\conda create -n comfyui python=3.11.9 -y
G:\miniconda311\condabin\conda activate comfyui
2025.6.5发布的ComfyUI版本v0.3.40
pytorch version: 2.7.1+cu128
Python version: 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]
conda中没有3.12.10,只有3.12.9、3.12.11(conda search python)
conda create -n comfyui_cp312 python=3.12.9 -y
conda activate comfyui_cp312
激活环境后,path环境变量就在首位添加了如下路径:
G:\miniconda311\envs\comfyui;
G:\miniconda311\envs\comfyui\Library\mingw-w64\bin;
G:\miniconda311\envs\comfyui\Library\usr\bin;
G:\miniconda311\envs\comfyui\Library\bin;
G:\miniconda311\envs\comfyui\Scripts;
G:\miniconda311\envs\comfyui\bin;
G:\miniconda311\condabin;
安装 PyTorch(GPU/CPU版):
NVIDIA GPU 用户:
comfyui指引中的命令行:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu124
安装指定版本的torch2.5.0+cu124:
pip install torch===2.5.0+cu124 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
torch太大了,有2.4g左右,用上面命令下载会较慢,可以用下载器去download.pytorch.org下载好后再安装要快很多,根据自己的cuda版本选择你要的版本下载。
torch whl下载好后使用命令先安装torch包:
pip install G:\wheel\cp311\torch-2.5.1+cu124-cp311-cp311-win_amd64.whl
使用下面命令安装对应版本的torchvision、orchaudio:
pip install torchvision===0.20.1+cu124 torchaudio===2.5.1+cu124 --index-url https://download.pytorch.org/whl/cu124
上面命令行参数--index-url、--extra-index-url 安装流程对比:
┌───────────────────────┐ ┌───────────────────────┐
│ --index-url │ │ --extra-index-url │
├───────────────────────┤ ├───────────────────────┤
│ 1. 仅检查指定URL │ │ 1. 先检查PyPI │
│ 2. 找不到则报错 │ │ 2. 找不到则检查额外URL │
└───────────────────────┘ └───────────────────────┘
版本对应:
torch | torchaudio | torchvision | xformers | 备注 | CUDA版本 | 支持的torch版本 | |
2.4.0 | 2.4.0 | 0.19.0 | 0.0.27.post1、0.0.27.post2 | 11.7 | 1.13.0--2.0.1 | ||
2.4.1 | 2.4.1 | 0.19.1 | 0.0.28 、0.0.28.post1 | 不建议安装这2个版本的torch, 因为这2个版本没找到flash_attn预编译whl | 11.8 | 2.0.0--2.5.1 | |
2.5.0 | 2.5.0 | 0.20.0 | 0.0.28.post2 | 12.1 | 2.1.0--2.5.1 | ||
2.5.1 | 2.5.1 | 0.20.1 | 0.0.28.post3、0.0.29.post1 | 12.4 | 2.4.0--2.5.1 | ||
2.6.0 | 2.6.0 | 0.21.0 | 0.0.29.post2、0.0.29.post3 |
安装过程中遇到较大难下载的模块(例如:scipy-1.15.2-cp311-cp311-win_amd64.whl ,41.2 MB),都可以下载whl文件进行安装。
三、安装 ComfyUI
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUIpip install -r requirements.txt
ModuleNotFoundError: No module named 'yaml'
该错误信息需要安装的模块其实是:pyyaml
四、启动 ComfyUI
ComfyUI启动命令行全部参数:
usage: main.py [-h] [--listen [IP]] [--port PORT] [--tls-keyfile TLS_KEYFILE] [--tls-certfile TLS_CERTFILE]
[--enable-cors-header [ORIGIN]] [--max-upload-size MAX_UPLOAD_SIZE] [--base-directory BASE_DIRECTORY]
[--extra-model-paths-config PATH [PATH ...]] [--output-directory OUTPUT_DIRECTORY]
[--temp-directory TEMP_DIRECTORY] [--input-directory INPUT_DIRECTORY] [--auto-launch]
[--disable-auto-launch] [--cuda-device DEVICE_ID] [--cuda-malloc | --disable-cuda-malloc]
[--force-fp32 | --force-fp16]
[--fp32-unet | --fp64-unet | --bf16-unet | --fp16-unet | --fp8_e4m3fn-unet | --fp8_e5m2-unet]
[--fp16-vae | --fp32-vae | --bf16-vae] [--cpu-vae]
[--fp8_e4m3fn-text-enc | --fp8_e5m2-text-enc | --fp16-text-enc | --fp32-text-enc]
[--force-channels-last] [--directml [DIRECTML_DEVICE]] [--oneapi-device-selector SELECTOR_STRING]
[--disable-ipex-optimize] [--preview-method [none,auto,latent2rgb,taesd]] [--preview-size PREVIEW_SIZE]
[--cache-classic | --cache-lru CACHE_LRU]
[--use-split-cross-attention | --use-quad-cross-attention | --use-pytorch-cross-attention | --use-sage-attention | --use-flash-attention]
[--disable-xformers] [--force-upcast-attention | --dont-upcast-attention]
[--gpu-only | --highvram | --normalvram | --lowvram | --novram | --cpu] [--reserve-vram RESERVE_VRAM]
[--default-hashing-function {md5,sha1,sha256,sha512}] [--disable-smart-memory] [--deterministic]
[--fast [FAST ...]] [--dont-print-server] [--quick-test-for-ci] [--windows-standalone-build]
[--disable-metadata] [--disable-all-custom-nodes] [--multi-user]
[--verbose [{DEBUG,INFO,WARNING,ERROR,CRITICAL}]] [--log-stdout]
[--front-end-version FRONT_END_VERSION] [--front-end-root FRONT_END_ROOT]
[--user-directory USER_DIRECTORY] [--enable-compress-response-body]
ComfyUI 常用启动参数列表说明
参数 作用 示例 --windows-standalone-build
启用便携模式,所有配置文件、插件、模型存储在 ComfyUI 目录内 python main.py --windows-standalone-build
--listen
指定服务监听地址(默认 127.0.0.1
,设为0.0.0.0
允许远程访问)--listen 0.0.0.0
--port
设置 Web 服务端口(默认 8188
)--port 9000
--dont-upcast-attention
禁用注意力机制的上采样(节省显存,可能影响生成质量) --dont-upcast-attention
--force-fp16
强制使用 FP16 精度(兼容性模式,适用于旧 GPU) --force-fp16
--cpu
强制使用 CPU 计算(即使检测到 GPU) --cpu
--disable-xformers
禁用 xFormers 优化(解决某些模型兼容性问题) --disable-xformers
--log-level
设置日志级别( debug
/info
/warning
/error
,默认info
)--log-level warning
--auto-launch
启动后自动打开浏览器 --auto-launch
--help
显示完整参数帮助信息 --help
-s
是 Python 解释器的标准参数,用于 禁用用户级包目录(site-packages
)的自动加载。
参数 作用 -S
禁用所有 site
模块的导入(更严格)-s
仅禁用用户级 site-packages
--isolated
完全隔离模式(相当于 -S -E -s
)
根据上面相关参数指引,建立启动文件如下:run_conda_comfyui.bat ,点击启动文件即可
call G:\miniconda311\condabin\conda activate comfyui
python.exe -s main.py --auto-launch
pause
五、安装ComfyUI_NTCosyVoice
构建好comfyui环境后,如果手动安装节点,也是需要使用命令先激活环境,激活后就与comfyui便携版一样了。
G:\miniconda311\condabin\conda activate comfui
git clone https://github.com/muxueChen/ComfyUI_NTCosyVoice.git
安装依赖custom_nodes\ComfyUI_NTCosyVoice\requirements.txt 时,deepspeed需要从 pypi 下载whl安装,版本可以不按requirements.txt中的要求(好像所有依赖的版本都可以高于文件中要求的),另外,安装依赖 WeTextProcessing要用如下命令安装pynini:
因为WeTextProcessing依赖pynini==2.1.6(可能会依据WeTextProcessing版本的更新而不同,当安装失败时,根据提示要求的安装相应版本即可),所以务必指明:
conda install -c conda-forge pynini==2.1.6
安装好deepspeed、pynini后,我的环境中,只需要安装以下依赖项即可:
将下面行保存的文本rr.txt,并执行安装pip install -r rr.txt
conformer
grpcio-tools
modelscope
hydra-core
HyperPyYAML
inflect
librosa
lightning
modelscope
omegaconf
openai-whisper
tensorboard
tensorrt-cu12
tensorrt-cu12-bindings
tensorrt-cu12-libs
WeTextProcessing
安装好deepspeed、pynini后,修改requirements.txt删除deepspeed项再安装依赖。
在 https://github.com/kylebgorman/pynini/issues/90 问题讨论中,说到在不支持 Windows ,要在windows中使用,可以通过WSL系统或conda。
安装完后,将模型文件下载到文件夹 G:\miniconda311\ComfyUI\custom_nodes\ComfyUI_NTCosyVoice\pretrained_models\CosyVoice2-0.5B 中 ,执行下面命令下面模型:
python downloadmodel.py
运行成功:
一开始虽然 ComfyUI_NTCosyVoice装上了,但运行时报了不少错误,最后发现是安装依赖时有些没装好(没装上),再依次装上后就OK了,迟点附上我环境中各依赖项的版本。
requirements.txt依赖项要求版本与实际安装版本不一致的模块 | ||
Package | 要求的版本 | 实际安装的版本 |
deepspeed | 0.14.2 | 0.16.4 |
diffusers | 0.27.2 | 0.32.2 |
huggingface-hub | 0.25.2 | 0.29.1 |
librosa | 0.10.2 | 0.10.2.post1 |
networkx | 3.1 | 3.4.2 |
protobuf | 4.25 | 4.25.6 |
pydantic | 2.7.0 | 2.10.6 |
rich | 13.7.1 | 13.9.4 |
transformers | 4.40.1 | 4.49.0 |
所以,可以将 requirements.txt 修改如下再安装依赖包:
conformer==0.3.2
#deepspeed>=0.14.2
diffusers>=0.27.2
gdown==5.1.0
grpcio==1.57.0
grpcio-tools==1.57.0
huggingface-hub>=0.25.2
modelscope
hydra-core==1.3.2
HyperPyYAML==1.2.2
inflect==7.3.1
librosa>=0.10.2
lightning==2.2.4
matplotlib==3.7.5
modelscope==1.15.0
networkx>=3.1
omegaconf==2.3.0
openai-whisper
protobuf>=4.25
pydantic>=2.7.0
rich>=13.7.1
soundfile==0.12.1
tensorboard
tensorrt-cu12
tensorrt-cu12-bindings
tensorrt-cu12-libs
transformers>=4.40.1
wget==3.2
WeTextProcessing>=1.0.3
onnxruntime-gpu
#torch
#torchvision
#torchaudio
安装中,遇到缺失的模块,依次安装就是了,我遇到了下面的缺失模块:
ModuleNotFoundError: No module named 'yaml' -------->pyyaml
'safetensors'
einops
transformers
torchsde
aiohttp
--------------
spandrel
kornia
llvmlite
六、关于 Miniconda 中配置的环境
激活步骤二中配置的环境,并利用该环境启动原来便携版本中的comfyui,由于该环境已经安装了节点ComfyUI_NTCosyVoice的依赖项,所以原便携版中安装的节点ComfyUI_NTCosyVoice导入成功,而别的节点(ComfyUI-Easy-Use),由于还未安装节点所需的依赖,导入失败:
而要让ComfyUI_NTCosyVoice真正跑起来,还需要将节点所需模块放置到合适的路径中即可。
一个新环境,除了安装Comfyui的requirements.txt外,再安装ComfyUI-Crystools\requirements.txt,好像很多节点就能导入成功了。剩下失败的,通过wps表格,筛选出缺失的模块,再生成 requirements.txt 安装应该就可以了: