用Miniconda安装comfyui、ComfyUI_NTCosyVoice

 由于在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                  │
└───────────────────────┘               └───────────────────────┘ 

版本对应: 

torchtorchaudiotorchvisionxformers备注 CUDA版本支持的torch版本
2.4.0 2.4.0 0.19.00.0.27.post1、0.0.27.post2  11.71.13.0--2.0.1
2.4.12.4.10.19.10.0.28  、0.0.28.post1​不建议安装这2个版本的torch,
因为这2个版本没找到flash_attn预编译whl
 11.82.0.0--2.5.1
2.5.02.5.00.20.00.0.28.post2 12.12.1.0--2.5.1
2.5.12.5.10.20.10.0.28.post3、0.0.29.post1  12.42.4.0--2.5.1
2.6.02.6.00.21.00.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 ComfyUI

pip 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 要求的版本实际安装的版本
deepspeed0.14.20.16.4
diffusers0.27.20.32.2
huggingface-hub0.25.20.29.1
librosa0.10.20.10.2.post1
networkx3.13.4.2
protobuf4.254.25.6
pydantic2.7.02.10.6
rich13.7.113.9.4
transformers4.40.14.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 安装应该就可以了:

### 与 ComfyUI 相关的库或资源 以下是几个与 ComfyUI 相关的重要库和资源,这些工具可以扩展 ComfyUI 的功能并提升用户体验: 1. **ComfyUI_GLSLNodes** 这是一个专门为 ComfyUI 开发的 GLSL 节点库,允许用户通过自定义的 GLSL 着色器实现高级图像处理效果[^1]。该项目托管在 GitCode 上,可以通过以下链接访问:[https://gitcode.com/gh_mirrors/co/comfyui_glslnodes](https://gitcode.com/gh_mirrors/co/comfyui_glslnodes)。 2. **Miniconda 安装支持** 对于需要更灵活环境配置的用户,Miniconda 提供了一种有效的方式来安装和管理 ComfyUI 及其相关依赖项[^3]。这种方法尤其适用于那些希望集成额外节点(如 ComfyUI_NTCosyVoice)以实现文本转语音功能的用户。 3. **Stable Diffusion 模型兼容性** ComfyUI 默认支持 Stable Diffusion 1.5 检查点,并且可以通过额外配置支持 Stable Diffusion XL 检查点[^4]。这为用户提供了更大的模型选择自由度,以满足不同的生成任务需求。 4. **社区贡献节点** ComfyUI 的生态系统中包含许多由社区开发者贡献的节点,例如用于音频处理、文本生成和其他创意任务的节点。用户可以通过搜索 GitHub 或其他代码托管平台找到这些资源。 ```python # 示例:如何检查当前安装ComfyUI 节点 import os def list_comfyui_nodes(directory): if os.path.exists(directory): nodes = [f for f in os.listdir(directory) if f.endswith('.py')] return nodes return [] # 假设节点存储在以下路径 node_directory = "./custom_nodes" print(list_comfyui_nodes(node_directory)) ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值