Usage Guide
Basic Usage
Once installed and configured, auto-uv-env works automatically:
# Navigate to a Python project
cd my-python-project/
# auto-uv-env automatically:
# 1. Detects pyproject.toml
# 2. Reads required Python version
# 3. Creates virtual environment if needed
# 4. Activates the environment
# You'll see:
# π Setting up Python 3.11 with UV...
# β
Virtual environment created
# π UV environment activated (Python 3.11.5)
# Your shell prompt may show the active Python version
(3.11.5) my-python-project $
# Leave the directory
cd ..
# β¬οΈ Deactivated UV environment
Configuration Options
Environment Variables
Control auto-uv-env behavior with these environment variables:
# Suppress all status messages
export AUTO_UV_ENV_QUIET=1
# Use custom virtual environment name (default: .venv)
export AUTO_UV_ENV_VENV_NAME=.virtualenv
# Access current Python version in your prompt
# This is automatically set when an environment is active
echo $AUTO_UV_ENV_PYTHON_VERSION # e.g., "3.11.5"
Per-Project Configuration
pyproject.toml Example
[project]
name = "my-awesome-project"
version = "0.1.0"
requires-python = ">=3.11,<3.13" # auto-uv-env uses this
[project.dependencies]
django = "^4.2"
requests = "^2.31"
Disabling for Specific Directories
Create a .auto-uv-env-ignore
file to disable auto-uv-env:
# Disable in current directory
touch .auto-uv-env-ignore
# Useful when using other tools like direnv
echo "Using direnv for this project" > .auto-uv-env-ignore
Working with Existing Virtual Environments
auto-uv-env respects existing virtual environments:
- Manual venvs are protected: If you manually activate a venv, auto-uv-env wonβt deactivate it
- Existing .venv is reused: If
.venv
already exists, auto-uv-env will use it - State tracking: Only deactivates environments it activated
Command Line Interface
Available Commands
# Show version
auto-uv-env --version
# Output: auto-uv-env 1.0.4
# Show help
auto-uv-env --help
# Check if environment should be activated (safe mode)
auto-uv-env --check-safe
# Output: {"activate": true, "venv": ".venv", "python": "3.11"}
# Show diagnostic information
auto-uv-env --diagnose
# Shows: UV version, Python detection, shell info
# Validate configuration
auto-uv-env --validate
# Checks all components are working correctly
Advanced Usage
Custom Shell Prompts
Zsh with Python Version
# Add to ~/.zshrc
PROMPT='${AUTO_UV_ENV_PYTHON_VERSION:+(π $AUTO_UV_ENV_PYTHON_VERSION) }%~ %# '
Bash with Python Version
# Add to ~/.bashrc
PS1='${AUTO_UV_ENV_PYTHON_VERSION:+(π $AUTO_UV_ENV_PYTHON_VERSION) }\w $ '
Fish with Python Version
# Add to ~/.config/fish/config.fish
function fish_prompt
if set -q AUTO_UV_ENV_PYTHON_VERSION
echo -n "(π $AUTO_UV_ENV_PYTHON_VERSION) "
end
echo -n (prompt_pwd) ' $ '
end
Integration with Other Tools
VS Code
VS Code will automatically detect the .venv
created by auto-uv-env. No additional configuration needed!
PyCharm
Point PyCharm to use .venv/bin/python
as the project interpreter.
Jupyter
# Install ipykernel in your environment
pip install ipykernel
# Register the kernel
python -m ipykernel install --user --name=myproject
Troubleshooting
Environment Not Activating
- Check for pyproject.toml:
ls pyproject.toml
- Verify UV is installed:
which uv
- Run diagnostics:
auto-uv-env --diagnose
Wrong Python Version
- Check pyproject.toml:
grep requires-python pyproject.toml
- Verify UV has the Python version:
uv python list
- Install missing Python version:
uv python install 3.11
Performance Issues
auto-uv-env v1.0.7 includes major performance optimizations:
- Shell startup overhead: 2-3ms (Python projects), 0ms (non-Python directories)
- Directory change overhead: <1ms per
cd
command - First-time environment creation: 1-5 seconds (UV creates the virtual environment)
- Subsequent activations: Near-instant (uses cached environment)
Key optimizations in v1.0.7:
- Lazy loading (no execution for non-Python directories)
- Command path caching
- Native bash TOML parsing (no Python subprocess)
- Shell built-ins instead of external commands
If experiencing slow directory changes:
- Verify you have the latest version:
auto-uv-env --version # Should be 1.0.7 or later
- Check for shell conflicts:
# Temporarily disable other shell plugins # Check if performance improves
- Use quiet mode for best performance:
export AUTO_UV_ENV_QUIET=1
- Report persistent issues:
auto-uv-env --diagnose > diagnostic.txt # Share at: https://github.com/ashwch/auto-uv-env/issues
Best Practices
- Always use pyproject.toml - Itβs the modern Python standard
- Specify Python version - Use
requires-python
for consistency - Commit .gitignore - Add
.venv/
to your.gitignore
- Use UV for packages -
uv pip install
instead ofpip install
- Donβt mix activation methods - Let auto-uv-env handle activation
- Use .auto-uv-env-ignore - When using other virtual environment tools
Examples
Django Project
[project]
name = "my-django-app"
requires-python = ">=3.11"
[project.dependencies]
django = ">=4.2"
psycopg2-binary = ">=2.9"
python-decouple = ">=3.8"
Data Science Project
[project]
name = "data-analysis"
requires-python = ">=3.10,<3.12"
[project.dependencies]
pandas = ">=2.0"
numpy = ">=1.24"
matplotlib = ">=3.7"
jupyter = ">=1.0"
FastAPI Project
[project]
name = "api-service"
requires-python = ">=3.11"
[project.dependencies]
fastapi = ">=0.104"
uvicorn = {extras = ["standard"], version = ">=0.24"}
pydantic = ">=2.4"