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
Check which Python is currently active: which python (or where python on Windows)
Confirm the virtual environment is activated - the shell prompt should show (venv)
Install using the environment's own interpreter: python -m pip install package-name
List installed packages to confirm it landed in the right place: python -m pip list
In an IDE, verify the selected interpreter path points to the venv, not the system Python
Recreate the venv if it's in a broken or mixed state: python -m venv venv
Avoid installing globally then expecting the package inside an isolated venv
For Jupyter, install ipykernel inside the venv and explicitly select that kernel
Found an issue with this solution?
