uv Python Virtual Environment Usage
uv is a fast Python package manager that creates isolated virtual environments in .venv/ by default. Scripts run directly with python won’t find packages installed via uv unless the venv is activated or uv run is used.
Why / When to Use
When you install packages with uv pip install and then run a script — especially from a cron job or a different shell — the system Python is used instead of the venv Python, causing ModuleNotFoundError.
Core Concept / Commands
Run a script using the uv venv
uv run python script.pyThis is the safest approach — no manual activation needed, works reliably from cron.
Activate the venv manually
source .venv/bin/activate
python script.pyInstall a package into the project venv
uv pip install requestsCheck which Python is active
which python
# Should show .venv/bin/python if venv is activeKey Options / Variants
Cron job with uv run
0 * * * * cd /path/to/project && uv run python script.pyAlways cd to the project directory first so uv finds the .venv folder.
Using uv with pip-style requirements
uv pip install -r requirements.txtGotchas
uv pip installinstalls into.venv/in the current directory — running the script from a different directory means a different.venv(or none).- Cron jobs that ran as root previously may have created state files owned by root that your user script can’t write. Fix:
sudo rm /tmp/<state-file>. - If you see “No module named X” after installing, check
which python— you’re likely using the system Python.
Source
Conversation “Zsh home button not working” and “Cron job scheduling issue” — 2026-05-15