Install NumPy with pip and verify it works
How to install NumPy with pip in a virtual environment, verify the install from a Python interpreter, and fix the two errors that break it most often.
Updated August 26, 2023
How to install NumPy with pip in a virtual environment, verify the install from a Python interpreter, and fix the two errors that break it most often.
NumPy is the library Python uses to handle numerical data. It gives you arrays, matrices, and the math operations that run on them, and it sits underneath most of the scientific Python stack: pandas builds on it for data manipulation, SciPy for advanced math, Matplotlib for plotting.
Why NumPy matters
- Efficient arrays: NumPy arrays store and manipulate large datasets far more efficiently than standard Python lists.
- Math built for arrays: Element-wise addition and multiplication, dot products, linear algebra routines, trigonometric functions, and much more, all optimized to run across a whole array at once.
- Everything else depends on it: Learn NumPy and you have the foundation for the rest of the scientific Python stack, including data analysis, machine learning, and scientific modeling.
Before you start
Check that Python is installed and see which version you have:
python3 --version
On Windows, use the Python launcher instead:
py --version
If neither command works, download the latest version from https://www.python.org/downloads/
The current NumPy release needs Python 3.12 or newer. On an older Python, pip will quietly install an older NumPy that still supports it, so the install succeeds but you get a different version than a tutorial might assume.
Install NumPy
Install NumPy into a virtual environment rather than into your system Python. A virtual environment is a private folder holding its own copy of Python and its own packages, so what you install for one project can’t break another one, or your operating system.
Create one in your project folder:
python3 -m venv .venv
Then activate it. On macOS and Linux:
source .venv/bin/activate
On Windows:
.venv\Scripts\activate
Your prompt will change to show (.venv). That means the environment is active, and python and pip now both refer to it. Install NumPy:
python -m pip install numpy
pip is Python’s package installer. It downloads NumPy from PyPI and installs it into the active environment.
Use python -m pip rather than a bare pip. A bare pip is a separate program on your PATH, and it isn’t guaranteed to belong to the Python you’ll actually run. python -m pip asks a specific interpreter to install into itself, so the two can never disagree.
When you’re done working, deactivate returns you to your normal shell. Next time, activate the environment again before you run anything.
If you already work in conda, conda install numpy into a conda environment does the same job. Don’t mix the two in one environment.
Verify the install
With the environment still active, open a Python interpreter by typing python, then run:
import numpy as np
print(np.__version__)
print(np.array([1, 2, 3]) * 2)
You’ll see something like:
2.5.2
[2 4 6]
Your version number will differ. The second line matters more than it looks: NumPy is mostly compiled C under a Python wrapper, and doing real arithmetic confirms the compiled part loaded, not just that the package folder exists.
When the install fails
Two errors account for most broken NumPy installs. Both are about which Python you’re talking to, not about NumPy itself.
error: externally-managed-environment
You ran pip install numpy against a Python that your operating system manages — Homebrew Python on a Mac, or the system Python on Debian, Ubuntu, and most other Linux distributions. Those installations refuse package installs on purpose, because overwriting their packages can break tools the OS depends on.
The error text suggests --break-system-packages. Don’t use it for a library like NumPy; it does what the name says. Create a virtual environment as described above and install there instead. That’s what the error is steering you toward.
ModuleNotFoundError: No module named 'numpy'
The install reported success, but the import fails. This means you installed into one Python and are running another — the most common trap in Python packaging, and a confusing one, because nothing appeared to go wrong.
Check that you’re pointed at the environment you think you are:
python -c "import sys; print(sys.executable)"
If that path isn’t inside your .venv folder, the environment isn’t active. Activate it and try the import again. If it is active and NumPy still isn’t found, install it into that specific interpreter with python -m pip install numpy.
Keeping pip current avoids a separate class of problem, where an old pip can’t read the newest wheel formats and falls back to building NumPy from source:
python -m pip install --upgrade pip
Where to go next
Once print(np.__version__) gives you a version number, you’re ready to start writing NumPy code. Two ideas are worth learning early, because they’re what makes NumPy fast:
- Vectorization: operate on whole arrays instead of looping over individual elements. NumPy is optimized for vectorized operations, so the same work finishes much faster.
- Broadcasting: NumPy can operate on arrays of different shapes when their dimensions are compatible, which saves you from writing explicit loops.
Both show up as soon as you start creating NumPy arrays and using NumPy.
For setups this guide doesn’t cover:
- Installing NumPy on a Mac
- Installing NumPy in Jupyter Notebook
- Installing NumPy in PyCharm
- Installing NumPy in Visual Studio Code
And if you need to check whether NumPy is already installed or update it to a newer version, those are covered separately.


