| title | Python venv troubleshoot — activation and path mismatches | ||||||
|---|---|---|---|---|---|---|---|
| domain | python | ||||||
| tags |
|
||||||
| status | published | ||||||
| lang | en | ||||||
| source | uncledad96-glitch | ||||||
| translated_from | lessons/contrib/python-venv-troubleshoot.md | ||||||
| created | 2026-07-22 | ||||||
| updated | 2026-07-22 | ||||||
| confidence | 0.9 |
python still points at system Python after “activating” a venv. pip install hits PEP 668 externally-managed-environment, or modules import from the wrong prefix. Overnight agents fail package installs.
- Activation script not sourced (run as
./activateinstead ofsource). - Wrong shell (fish needs
activate.fish). - Nested shells / cron without activation.
- Ubuntu/Debian PEP 668 blocks system pip.
python3 -m venv .venv
# bash/zsh
source .venv/bin/activate
# fish
# source .venv/bin/activate.fish
which python
python -c "import sys; print(sys.prefix)"
# must show .../.venv
python -m pip install -U pip
python -m pip install -r requirements.txtCron / no-TTY:
/home/you/proj/.venv/bin/python script.py
# or
export PATH="/home/you/proj/.venv/bin:$PATH"test "$(python -c 'import sys; print(sys.prefix)')" = "$(pwd)/.venv" || \
test -x .venv/bin/python
python -m pip check- Prefer
python -m pipover barepip. - Never
sudo pip installinto system Python for agent jobs. - Pair with the pip SSL/timeout EN lesson when installs hang.