comfy-cli icon indicating copy to clipboard operation
comfy-cli copied to clipboard

Globally installed comfy-cli does not respect activated venv

Open zdaar opened this issue 7 months ago • 2 comments

Describe the bug I installed comfy-cli globally (outside any venv) and activated a local conda venv

conda activate .\venv\

comfy cli does not work when called.

examples :

comfy node save-snapshot
Execute from: D:\AI\ComfyUI

Execution error: ['C:\\AI\\python.exe',
'D:\\AI\\ComfyUI\\custom_nodes\\ComfyUI-Manager\\cm-cli.py', 'save-snapshot']
python D:\AI\ComfyUI\custom_nodes\ComfyUI-Manager\cm-cli.py save-snapshot

WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `custom_nodes/ComfyUI-Manager/../../` as the ComfyUI
path.
[ComfyUI-Manager] The ComfyRegistry cache update is still in progress, so an outdated cache is being used.
FETCH DATA from: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json [DONE]
Current snapshot is saved as `2025-05-17_13-05-33_snapshot.json`
comfy launch

Launching ComfyUI from: D:\AI\ComfyUI

Adding extra search path checkpoints stuff here

Failed to execute startup-script: D:\AI\ComfyUI\custom_nodes\ComfyUI-Manager\prestartup_script.py / No module named 'huggingface_hub'

Prestartup times for custom nodes:
   0.0 seconds: D:\AI\ComfyUI\custom_nodes\rgthree-comfy
   0.0 seconds: D:\AI\ComfyUI\custom_nodes\comfyui-easy-use
   1.4 seconds (PRESTARTUP FAILED): D:\AI\ComfyUI\custom_nodes\ComfyUI-Manager

Traceback (most recent call last):
  File "D:\AI\ComfyUI\main.py", line 128, in <module>
    import comfy.utils
  File "D:\AI\ComfyUI\comfy\utils.py", line 20, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'

To Reproduce Create a local conda env

conda create -p ./venv python=3.11

Install comfy-cli globally (outside the env)

pip install comfy-cli

Activate the local conda env

conda activate ./venv

Run any comfy-cli command that wraps internal scripts:

comfy node save-snapshot

It fails silently or errors out. The subprocess is spawned with the global Python (not the active conda env), so we get dependencies failure Running the same commands directly through python inside the env works as expected:

python custom_nodes/ComfyUI-Manager/cm-cli.py save-snapshot

Expected behavior The comfy CLI does not detect or honor the active conda environment, it should

Additional context Should have been fixed in #75 but its not for me

Installing it inside the conda venv works straight out of the box

pip uninstall comfy-cli
...
Successfully uninstalled comfy-cli-1.3.9

conda activate .\venv\

pip install comfy-cli
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
Collecting comfy-cli
  Downloading comfy_cli-1.3.9-py3-none-any.whl.metadata (10 kB)
Requirement already satisfied: charset-normalizer>=3.0.0 in e:\ai\_comfyui\311\comfyui\venv\lib\site-packages (from comfy-cli) (3.4.1)
...

comfy node save-snapshot
Execute from: D:\AI\ComfyUI
[ComfyUI-Manager] The ComfyRegistry cache update is still in progress, so an outdated cache is being used.
FETCH DATA from: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json [DONE]
Current snapshot is saved as `2025-05-17_13-19-08_snapshot.json

I am using Windows 11

zdaar avatar May 17 '25 11:05 zdaar

Hello @zdaar! I'm Dosu, a friendly bot here to help you with bugs, answer your questions, and assist you in becoming a contributor. I'm ready to assist while you wait for a human maintainer. Let's tackle your issue together!

The issue you're experiencing is due to comfy-cli using sys.executable to determine the Python interpreter for executing commands. This means it defaults to the Python interpreter that was used to install comfy-cli, which in your case is the global Python environment, not the activated conda environment [1].

To resolve this, you can either:

  1. Install comfy-cli within the conda environment: This ensures that the correct Python interpreter from the activated environment is used, as you've already discovered.

  2. Modify the PATH: Ensure that the conda environment's Python interpreter is first in your PATH when executing comfy-cli commands. This might involve adjusting your environment variables or using a wrapper script to call comfy-cli with the correct Python interpreter.

  3. Use a virtual environment-specific command: Instead of using the globally installed comfy-cli, you can directly call the script using the Python interpreter from the activated conda environment, as you've done with python custom_nodes/ComfyUI-Manager/cm-cli.py save-snapshot.

These approaches should help comfy-cli respect the activated conda environment and use its Python interpreter, resolving the dependency issues you're facing.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar May 17 '25 11:05 dosubot[bot]

Seems to be same root cause as #263

Interpause avatar Jun 04 '25 05:06 Interpause