Run uv sync --all-packages After Workspace Changes
Rule
After modifying workspace structure (adding dependencies or creating new packages), run 'uv sync --all-packages' to install all workspace packages and make them importable.
Context
In uv workspaces, packages can exist in the workspace configuration but not be installed in the virtual environment. This creates a disconnect where the workspace knows about packages, but Python cannot import them at runtime.
Detection
- ModuleNotFoundError when importing workspace packages that exist in pyproject.toml
- 'uv pip list | grep
' shows package NOT installed despite being in workspace - After adding new workspace packages or dependencies to existing packages
Pattern
When workspace structure changes:
- Verify package installation:
uv pip list | grep <package> - If missing, run:
uv sync --all-packages - Confirm all workspace packages are installed
- Test imports work correctly
# Check if package is installed
uv pip list | grep <package-name>
# If missing, sync all packages
uv sync --all-packages
# Verify installation
python3 -c "import <package_name>; print('OK')"
Outcome
- All workspace packages become importable immediately after sync
- Eliminates ModuleNotFoundError for workspace packages
- Ensures virtual environment matches workspace configuration
Related
- Configure pytest pythonpath - Related import configuration for tests