Homebrew vs System Python Conflict Fix (2026)
The Error
ImportError: No module named 'requests'
Python path: /usr/bin/python3 (macOS system Python 3.9.6)
Packages installed in: /opt/homebrew/lib/python3.12/site-packages/
Claude Code used system Python but packages are in Homebrew Python
This appears when Claude Code runs Python using the system binary while packages are installed under a different Homebrew Python installation.
The Fix
# Add to CLAUDE.md:
# Always use /opt/homebrew/bin/python3 for Python commands on this project.
# Never use bare 'python' or 'python3' as it may resolve to system Python.
- Tell Claude Code to use the full path to the correct Python.
- Verify which Python has your packages:
/opt/homebrew/bin/python3 -c "import requests". - Add the instruction to CLAUDE.md so it persists across sessions.
Why This Happens
macOS ships with a system Python at /usr/bin/python3 (often 3.9.x, read-only). Homebrew installs a newer Python at /opt/homebrew/bin/python3 (3.12+). pip install adds packages to whichever Python ran pip. If you installed packages with pip3 install requests and pip3 points to Homebrew Python, but Claude Code runs python3 script.py which resolves to system Python, the import fails because system Python does not have those packages.
If That Doesn’t Work
Check all Python installations and their package paths:
which -a python3
/usr/bin/python3 -c "import sys; print(sys.path)"
/opt/homebrew/bin/python3 -c "import sys; print(sys.path)"
Create an alias in your shell profile:
echo 'alias python3=/opt/homebrew/bin/python3' >> ~/.zshrc
echo 'alias pip3=/opt/homebrew/bin/pip3' >> ~/.zshrc
source ~/.zshrc
Use pyenv to manage Python versions consistently:
brew install pyenv
pyenv install 3.12.0
pyenv global 3.12.0
eval "$(pyenv init -)"
Prevention
# CLAUDE.md rule
Use /opt/homebrew/bin/python3 for all Python commands on macOS. Or use the project virtualenv: source .venv/bin/activate. Never rely on bare 'python3' resolving to the correct installation.
See Also
Related Error Messages
This fix also applies if you see variations of this error:
- Connection or process errors with similar root causes in the same subsystem
- Timeout variants where the operation starts but does not complete
- Permission variants where access is denied to the same resource
- Configuration variants where the same setting is missing or malformed
If your specific error message differs slightly from the one shown above, the fix is likely the same. The key indicator is the operation that failed (shown in the stack trace) rather than the exact wording of the message.
Frequently Asked Questions
Does this error affect all operating systems?
This error can occur on macOS, Linux, and Windows (WSL). The exact error message may differ slightly between platforms, but the root cause and fix are the same. macOS users may see additional Gatekeeper or notarization prompts. Linux users should check that the relevant system packages are installed. Windows users should ensure they are running inside WSL2, not native Windows.
Will this error come back after updating Claude Code?
Updates can occasionally reintroduce this error if the update changes default configurations or dependency requirements. After updating Claude Code, verify your project still builds and runs correctly. If the error returns, reapply the fix and check the changelog for breaking changes.
Can this error cause data loss?
No, this error occurs before or during an operation and does not corrupt existing files. Claude Code’s edit operations are atomic — they either complete fully or not at all. However, if the error occurs during a multi-step operation, you may have partial changes that need to be reviewed with git diff before continuing.
How do I report this error to Anthropic if the fix does not work?
Open an issue at github.com/anthropics/claude-code with: (1) the full error message including stack trace, (2) your Node.js version (node --version), (3) your Claude Code version (claude --version), (4) your operating system and version, and (5) the command or operation that triggered the error.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.