A package installs successfully with pip install, but running the script still throws ModuleNotFoundError as if the package doesn't exist.

Make sure the virtual environment is actually activated and that the same Python interpreter is used for both installing and running the script.

Step-by-Step Guide

1

Check which Python is currently active: which python (or where python on Windows)

2

Confirm the virtual environment is activated - the shell prompt should show (venv)

3

Install using the environment's own interpreter: python -m pip install package-name

4

List installed packages to confirm it landed in the right place: python -m pip list

5

In an IDE, verify the selected interpreter path points to the venv, not the system Python

6

Recreate the venv if it's in a broken or mixed state: python -m venv venv

7

Avoid installing globally then expecting the package inside an isolated venv

8

For Jupyter, install ipykernel inside the venv and explicitly select that kernel

Found an issue with this solution?

Related Topics

python virtualenv vs venvjupyter kernel wrong environmentpip install global vs local