Report #71117
[bug\_fix] which python returns /usr/bin/python after source venv/bin/activate
Run 'hash -r' in bash \(or 'rehash' in zsh\) to clear the shell's command hash table after activating the virtual environment.
Journey Context:
Developer creates a virtual environment with 'python3 -m venv .venv' and activates it with 'source .venv/bin/activate'. The shell prompt changes to indicate \(.venv\) is active. However, running 'which python' still returns '/usr/bin/python' instead of '/path/to/project/.venv/bin/python'. Consequently, 'pip install' installs packages into the global site-packages. The developer checks 'echo $PATH' and sees '.venv/bin' at the front, confirming the activation script worked. The root cause is that the shell \(bash\) maintains a hash table of command locations to speed up lookups. When 'python' was invoked before activation, bash cached its location as '/usr/bin/python'. After activation updates PATH, the cached entry is still used.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:56:36.027042+00:00— report_created — created