fix: use correct Python executable for workspace operations#375
Merged
fix: use correct Python executable for workspace operations#375
Conversation
When comfy-cli is installed via pipx or uv tool, sys.executable points to their isolated venv, not the environment where ComfyUI deps belong. This caused install, launch, node, and update commands to target the wrong Python. Add comfy_cli/resolve_python.py with centralized resolution: VIRTUAL_ENV -> CONDA_PREFIX -> workspace .venv/venv -> sys.executable. During comfy install, a workspace .venv is created when no active env is detected. All ~20 sys.executable callsites across 6 files now use the resolved python instead. Fixes #263, fixes #272. Supersedes #282.
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #375 +/- ##
==========================================
+ Coverage 54.89% 60.49% +5.60%
==========================================
Files 32 33 +1
Lines 3618 3678 +60
==========================================
+ Hits 1986 2225 +239
+ Misses 1632 1453 -179
🚀 New features to boost your workflow:
|
Verify that each callsite (install, launch, cm_cli, custom_nodes, cmdline, models) actually wires the resolved python into subprocess calls rather than falling back to sys.executable.
f53311c to
07cb00e
Compare
This was referenced Mar 13, 2026
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When comfy-cli is installed via pipx or uv tool, sys.executable points to their isolated venv rather than the environment where ComfyUI dependencies should go. This means comfy install puts torch into comfy-cli's own venv, comfy launch runs main.py with the wrong Python, and comfy node install targets the wrong pip.
The fix adds a small resolve_python module that checks, in order: VIRTUAL_ENV, CONDA_PREFIX, workspace .venv or venv directory, then falls back to sys.executable. During comfy install, if no active environment is detected, a .venv is created inside the workspace automatically. All ~20 sys.executable callsites across install.py, launch.py, command.py, cm_cli_util.py, cmdline.py, and models.py now go through this resolution instead of using sys.executable directly.
The validate_node_for_publishing ruff check intentionally stays on sys.executable since ruff is comfy-cli's own dev dependency, not a workspace dep.
Backward compatibility is preserved: if you pip install comfy-cli into an activated venv, that venv's python is used (via VIRTUAL_ENV). If you use conda, CONDA_PREFIX is respected. Existing installs that already have a workspace .venv or venv will find it. The sys.executable fallback means nothing changes for direct pip installs in a shared environment.
Fixes #263, fixes #272. Supersedes community PR #282 which took a similar approach but eagerly created venvs in more situations.