BugMedic

Python “No module named”: install it into the right interpreter

Install the package with python -m pip for the exact interpreter that runs your script.

By BugMedic editorial teamLast source review: 2026-09-29Windows, macOS, Linux

Make sure you install into the interpreter that runs the code: python -m pip install requests. If you use a virtual environment, activate it first. Note the import name can differ from the pip name (Pillow imports as PIL).

Try these fixes in order

01

Identify the running interpreter

Confirm which interpreter runs your script and where its packages live. Mismatched python and pip is the most common cause.

python -c "import sys; print(sys.executable)"
02

Install with python -m pip

Installing via python -m pip guarantees the package lands in that interpreter's site-packages, not some other Python's.

python -m pip install requests
03

Activate the right virtual environment

If the project uses a virtual environment, activate it in the current shell before installing or running.

source .venv/bin/activate
04

Verify the import

Verify the import resolves from the same interpreter, using the project's documented import name.

python -c "import requests; print(requests.__version__)"

Interpret what you see

pip install succeeded but the import still fails

What it suggests: pip and python point at different installations. Installing with bare pip put the package where your script's interpreter never looks.

Next check: Run python -m pip install requests using the same python that runs the script.

It works in one terminal but not another

What it suggests: The package is installed inside a virtual environment that is not activated in the shell running the script.

Next check: Activate the venv, or run the venv's python directly by path.

pip shows the package as installed

What it suggests: The PyPI distribution name and the import name differ (pip install scikit-learn imports as sklearn; Pillow imports as PIL).

Next check: Check the project's docs for the import name and import that instead.

Why this happens

  • The package was never installed for the interpreter running the script.
  • The package was installed into a different interpreter or virtual environment than the one running the code.

Still not working?

Do not install packages with sudo pip to fix this; it writes into system locations and can break OS-managed Python. Use a virtual environment or python -m pip for the right interpreter instead.

Official sources

These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.

Related Python guides