Python can report a NumPy import failure even when NumPy exists somewhere else on the same computer. The usual cause is that the script, notebook, service, or IDE is using a different interpreter than the one that received the package, while compiled-extension errors often come from a stale install or a package built against another NumPy version.
Keep the repair inside the runtime that raised the traceback. Running pip as python -m pip binds the installer to the same interpreter printed by sys.executable, which avoids repairing one environment while the failing process keeps using another.
Conda environments should use Conda first, and development checkouts should be cleaned or left before reinstalling because old build files can shadow the installed package. When the traceback leaves NumPy and names a package compiled against another NumPy version, repair that package in the same environment before pinning NumPy for compatibility.
Related: Install with pip
Related: Install with uv
Related: Install with Conda
Steps to fix the NumPy import error:
- Reproduce the NumPy import error from the failing runtime.
$ python -c "import numpy as np; print(np.__version__)" Traceback (most recent call last): File "<string>", line 1, in <module> import numpy as np; print(np.__version__) ^^^^^^^^^^^^^^^^^^ ModuleNotFoundError: No module named 'numpy'Run the check from the same terminal, IDE interpreter, notebook kernel, service, or job runner that reports the error. If the traceback says Python is importing from a NumPy source directory, leave that checkout before reinstalling.
- Identify the Python interpreter that raised the error.
$ python -c "import sys; print(sys.executable)" /work/.venv/bin/python
- Check that pip belongs to the same interpreter.
$ python -m pip --version pip 25.1.1 from /work/.venv/lib/python3.14/site-packages/pip (python 3.14)
The path and Python version should match the interpreter from the previous step. If they do not, activate the correct environment or change the IDE or notebook kernel before reinstalling.
- Reinstall NumPy through the package manager that owns the environment.
$ python -m pip install --upgrade --force-reinstall numpy Collecting numpy ##### snipped ##### Successfully installed numpy-2.5.0
For a Conda-managed environment, prefer conda install --force-reinstall numpy from the active environment. Avoid mixing pip and Conda repairs unless that environment was designed for both installers.
- Restart any long-running Python process that reported the error.
Notebook kernels, application servers, and background workers can keep old import paths or extension modules loaded until the process restarts.
- Verify that NumPy imports and runs an array operation.
$ python -c "import numpy as np; print(np.__version__); print(np.array([1, 2, 3]).sum())" 2.5.0 6
If the remaining traceback names a downstream package after a NumPy upgrade, upgrade or reinstall that package in the same environment first. Pin numpy<2 only when that package has no build compatible with current NumPy.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.