Managing Python Dependencies¶
Add, remove, and manage Python packages in your ComfyUI environment using UV-powered dependency management.
Overview¶
The py commands give you direct control over Python packages in your environment:
- py add - Install Python packages (requests, numpy, pillow, etc.)
- py remove - Uninstall packages you no longer need
- py list - View installed dependencies
- py uv - Direct UV access for advanced operations
All changes are tracked in .cec/pyproject.toml and committed with your environment for reproducibility.
Python packages vs custom nodes
cfd py add- For general Python libraries (requests, opencv-python, numpy)cfd node add- For ComfyUI custom nodes (automatically installs their Python dependencies)
Most of the time you'll use node add. Use py add when you need Python packages that aren't part of a custom node.
Before you begin¶
Make sure you have:
- An active environment —
cfd use <name>or use-e <name>flag - Internet connection for downloading packages from PyPI
Adding packages¶
Add Python packages to your environment:
What happens:
- UV resolution - Checks if package exists and resolves dependencies
- Updates pyproject.toml - Adds to
[project.dependencies] - Installs package - Downloads and installs in environment's
.venv - Tracks in git - Changes are ready to commit
Example output:
📦 Adding 1 package(s)...
✓ Added 1 package(s) to dependencies
Run 'cfd -e my-env status' to review changes
Adding multiple packages¶
Add several packages at once:
All packages are resolved together, ensuring compatibility.
Adding with version constraints¶
Specify version requirements:
# Minimum version
cfd py add "numpy>=1.24.0"
# Version range
cfd py add "torch>=2.0.0,<2.5.0"
# Exact version
cfd py add "pillow==10.0.0"
Quote version constraints
Always quote package specifications with special characters (>,<,=) to prevent shell interpretation:
Adding from requirements.txt¶
Install packages from a requirements file:
Example requirements.txt:
What happens:
- Reads all packages from the file
- Adds them to
[project.dependencies] - Resolves and installs as a batch
Requirements file location
The file path is relative to your current directory, not the environment:
Upgrading packages¶
Upgrade existing packages to their latest compatible versions:
This updates requests to the latest version that satisfies your constraints.
Upgrade from requirements file:
Upgrades all packages listed in the file.
Removing packages¶
Remove packages you no longer need:
What happens:
- Removes from pyproject.toml - Deletes from
[project.dependencies] - Uninstalls package - Removes from
.venv - Updates lockfile - Re-resolves remaining dependencies
Example output:
🗑 Removing 1 package(s)...
✓ Removed 1 package(s) from dependencies
Run 'cfd -e my-env status' to review changes
Removing multiple packages¶
Remove several packages at once:
Removing non-existent packages¶
ComfyDock safely handles packages that don't exist:
Output:
🗑 Removing 1 package(s)...
ℹ️ Package 'nonexistent-package' is not in dependencies (already removed or never added)
No error — the operation is idempotent.
Mixed removal¶
When removing multiple packages where some exist and some don't:
Output:
🗑 Removing 3 package(s)...
✓ Removed 2 package(s) from dependencies
ℹ️ Skipped 1 package(s) not in dependencies:
• nonexistent
Listing dependencies¶
View all Python packages in your environment:
Example output:
Dependencies (5):
• requests>=2.28.0
• pillow>=10.0.0
• tqdm>=4.65.0
• numpy>=1.24.0,<2.0.0
• opencv-python>=4.8.0
Understanding the output¶
- Shows packages from
[project.dependencies]in pyproject.toml - Includes version constraints as specified
- Does not show transitive dependencies (packages installed as dependencies of your packages)
Viewing all dependencies¶
Include custom node dependency groups:
Example output:
Dependencies (3):
• requests>=2.28.0
• pillow>=10.0.0
• tqdm>=4.65.0
node/comfyui-impact-pack (4):
• ultralytics>=8.0.0
• onnxruntime>=1.15.0
• opencv-python>=4.8.0
• segment-anything>=1.0
node/comfyui-controlnet-aux (6):
• mediapipe>=0.10.0
• timm>=0.9.0
• transformers>=4.30.0
• diffusers>=0.21.0
• einops>=0.7.0
• scipy>=1.11.0
This shows:
- Base dependencies - Added with
cfd py add - Node groups - Dependencies from each custom node
Node dependencies are isolated
Custom nodes get their own dependency groups like node/comfyui-impact-pack. This allows:
- Conflict detection - UV reports if two nodes need incompatible versions
- Clean removal - Removing a node removes its unique dependencies
- Transparency - See exactly what each node requires
Advanced usage¶
Power-user flags¶
ComfyDock exposes advanced UV features for power users:
Adding to dependency groups¶
Add packages to optional dependency groups:
In pyproject.toml:
Use case: Organize packages by feature (cuda-specific, dev tools, optional extras).
Adding development dependencies¶
Mark packages as development-only:
In pyproject.toml:
Use case: Testing, linting, and development tools that aren't needed for production.
Editable installs¶
Install local packages in development mode:
This creates a symbolic link, so changes to the package source are immediately available without reinstalling.
Use case: Developing a Python package that your custom node depends on.
Version specifier styles¶
Control how UV writes version constraints:
# Lower bound only (default)
cfd py add numpy --bounds lower
# Result: numpy>=1.24.0
# Pin major version
cfd py add numpy --bounds major
# Result: numpy>=1.24.0,<2.0.0
# Pin minor version
cfd py add numpy --bounds minor
# Result: numpy>=1.24.0,<1.25.0
# Exact version
cfd py add numpy --bounds exact
# Result: numpy==1.24.0
Use case: Control how strict your version constraints are for reproducibility vs flexibility.
Direct UV access¶
For advanced operations not covered by py add/remove/list, use the UV passthrough:
This runs UV commands with proper environment context (working directory, environment variables).
Examples:
# Lock dependencies without syncing
cfd py uv lock
# Sync from lockfile without updating
cfd py uv sync --frozen
# Add to specific group with UV-specific flags
cfd py uv add --group optional-cuda sageattention --no-sync
# Show UV help
cfd py uv --help
Advanced users only
cfd py uv gives you direct access to UV. This is powerful but can break things if misused:
- No validation - ComfyDock doesn't check your commands
- Can corrupt state - Incorrect commands can break your environment
- Exit codes propagated - UV errors will exit with error codes
Use py add/remove/list unless you specifically need UV features.
Common patterns¶
Adding packages for a workflow¶
You download a workflow that needs specific Python packages:
# Add packages the workflow needs
cfd py add mediapipe timm transformers
# Verify they're installed
cfd py list
Setting up a development environment¶
You're developing custom nodes and need dev tools:
# Add dev dependencies
cfd py add pytest black ruff mypy --dev
# View all dependencies including dev
cfd py list --all
Migrating from requirements.txt¶
You have an existing ComfyUI setup with requirements.txt:
# Import all packages
cfd py add -r requirements.txt
# Remove old file (now tracked in pyproject.toml)
rm requirements.txt
Fixing version conflicts¶
Two custom nodes conflict on package versions:
# Check what's installed
cfd py list --all
# See the conflict
# node/comfyui-foo requires torch>=2.0,<2.1
# node/comfyui-bar requires torch>=2.1
# Force a specific version with constraints
cfd constraint add "torch==2.1.0"
# Repair to apply
cfd repair --yes
See Constraints for more on dependency constraints.
Upgrading all packages¶
Update all packages to latest compatible versions:
# Export current dependencies
cfd py list > /tmp/deps.txt
# Upgrade all
cfd py add -r /tmp/deps.txt --upgrade
Troubleshooting¶
Package not found¶
Error:
Solution:
- Verify package name on PyPI
- Check for typos (e.g.,
opencv-pythonnotopencv) - Ensure you have internet connection
Dependency conflict¶
Error:
Solution:
-
Check which packages require conflicting versions:
-
Use constraints to force a compatible version:
-
Or remove conflicting node:
See Resolving Node Conflicts for detailed conflict resolution.
Can't remove package¶
Error:
Solution:
This means other packages depend on it. You have two options:
-
Remove dependent packages first:
-
Force removal (not recommended - may break things):
Requirements file not found¶
Error:
Solution:
- Check file path is correct (relative to current directory)
- Use absolute path if needed:
Changes not taking effect¶
After adding packages, ComfyUI doesn't see them:
Solution:
-
Verify environment is active:
-
Check packages are installed:
-
Restart ComfyUI:
-
If still broken, repair environment:
How it works¶
Behind the scenes¶
When you run cfd py add:
- UV resolution - UV checks PyPI, resolves dependencies, detects conflicts
- Updates pyproject.toml - Adds package to
[project.dependencies] - Updates lockfile - Regenerates
uv.lockwith exact versions - Installs packages - Downloads wheels and installs in
.venv
Relationship to custom nodes¶
Custom nodes have their own dependency groups:
[project.dependencies]
# Your packages (via cfd py add)
requests = ">=2.28.0"
[project.optional-dependencies]
# Custom node packages (via cfd node add)
"node/comfyui-impact-pack" = [
"ultralytics>=8.0.0",
"onnxruntime>=1.15.0"
]
When you install a custom node with cfd node add, its Python dependencies are automatically added to the node's group. You rarely need to manually manage node dependencies.
Version tracking¶
All changes are tracked in .cec/:
# View changes
cfd status
# Commit changes
cfd commit -m "Added image processing dependencies"
# Changes now versioned with your environment
This means your Python dependencies are:
- Git-tracked - Full history of changes
- Reproducible - Others can recreate your environment
- Shareable - Push to remote, others can pull
Next steps¶
- Constraints - Override dependency versions with constraints
- Node Conflicts - Resolve dependency conflicts between nodes
- Version Control - Commit and track changes over time
- Export & Import - Share environments with full dependencies