Skip to content

Dependencies Installed in Wrong Environment When comfy-cli is Installed with Python Application Managers #263

@INFCode

Description

@INFCode

Describe the Bug

Currently, comfy-cli attempts to install dependencies into the environment it is running in. This can lead to incorrect behavior when comfy-cli is installed in a different (virtual) environment than ComfyUI. This situation often occurs when using Python application managers like pipx or uv tool, which isolate CLI tools in their own environments.

To Reproduce

  1. Ensure you have a Python application management tool installed (e.g., uv tool).

  2. Install comfy-cli using uv:

    uv tool install comfy-cli  

    This creates a dedicated environment for comfy-cli.

  3. Clone ComfyUI:

    git clone [email protected]:comfyanonymous/ComfyUI.git  
  4. Create and activate a virtual environment for ComfyUI:

    python3 -m venv comfy-env  
    source ./comfy-env/bin/activate  
  5. Run comfy install --restore.

Observed behavior:
Installation fails, complaining that pip is not available. The error indicates that it's trying to use the Python interpreter from the uv environment rather than the currently activated virtual environment.

  1. You want to apply the workaround suggested in Comfy Install fails - Pytorch dependencies #245 and run ensurepip for that Python. Although this fixes the issue itself, the logs would show that dependencies are installed into the comfy-cli environment, which is not the intended behavior.

Expected Behavior

comfy-cli should install dependencies into the virtual environment associated with ComfyUI, or at least respect the currently activated environment.

Nice to Have

  • Terminal output
  • Screenshots

Additional Context

In comfy_cli/command/install.py, sys.executable is used to determine the Python interpreter for pip install. However, this always resolves to the environment in which comfy-cli itself is running—not necessarily the one ComfyUI is intended to use.

A more robust approach might be to resolve python or pip via:

python_path = shutil.which("python", path=os.environ.get("PATH", ""))
pip_path = shutil.which("pip", path=os.environ.get("PATH", ""))

This would respect the user's shell environment and active virtualenv (or other environments like conda), aligning the install target more accurately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions