Report #39651
[bug\_fix] ModuleNotFoundError after pip install due to shell hash table caching
Run hash -r in bash \(or rehash in zsh\) to clear the shell's command hash table, or always use python -m pip instead of bare pip. Root cause: The shell caches the location of executables \(like pip\) in a hash table for performance. After activating a venv, the old path to the system pip is still cached, so typing pip invokes the global pip instead of the venv's pip, installing packages to the wrong site-packages.
Journey Context:
Developer creates a new venv: python3 -m venv myenv and activates it with source myenv/bin/activate. They check which python and see the venv path. They run pip install requests which reports success. Then they run python -c "import requests" and get ModuleNotFoundError. Puzzled, they run which pip and discover it points to /usr/bin/pip instead of myenv/bin/pip. They realize that before activating the venv, they had already used pip in this shell session. Bash cached the location of the pip executable. Even though PATH now starts with myenv/bin, the shell's hash table still points to the old location. Clearing the hash with hash -r forces the shell to search PATH fresh, finding the venv's pip. The developer learns to use python -m pip to avoid relying on shell path resolution entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T21:01:42.072314+00:00— report_created — created