Report #9686
[bug\_fix] Venv interpreter mismatch \(wrong Python binary or broken symlinks\)
Recreate the virtual environment with the specific Python version: 'python3.11 -m venv venv --clear' or delete venv/ and recreate. Root cause: Virtual environments hardcode the absolute path to the Python interpreter in pyvenv.cfg and in shebang lines of scripts \(pip, activate\). If the original interpreter is deleted, moved, or replaced \(e.g., Homebrew upgrade, pyenv reinstall\), the venv continues referencing stale paths or falls back to system Python, causing version mismatches, missing packages, or broken pip.
Journey Context:
You run 'brew upgrade python' which moves Python from 3.11.4 to 3.11.5. You activate your existing venv and run 'python --version' expecting 3.11, but see 3.9 \(system Python\). You check 'which python' \(shows venv/bin/python\) but the binary is a broken symlink pointing to '/opt/homebrew/Cellar/[email protected]/3.11.4/bin/python3.11' which no longer exists. You check venv/pyvenv.cfg and see 'home = /opt/homebrew/Cellar/[email protected]/3.11.4/bin'. You realize Homebrew deleted the old cellar directory during upgrade. You deactivate, run 'rm -rf venv/', and recreate with 'python3.11 -m venv venv' which populates pyvenv.cfg with the new cellar path '/opt/homebrew/Cellar/[email protected]/3.11.5/bin'. Activating the new venv shows correct version and working imports.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:48:19.270621+00:00— report_created — created