Skip to content

NumPy - Environment

NumPy is not part of the standard Python library, so you need to install it separately. The recommended way for most users is to use a package manager like pip or conda.

Section titled “Installation using Package Managers (Recommended)”

Using pip (Python’s standard package installer)

Section titled “Using pip (Python’s standard package installer)”

If you have Python and pip installed, you can install NumPy from the command line (Terminal on macOS/Linux, Command Prompt or PowerShell on Windows):

pip install numpy

This command downloads and installs the latest compatible version of NumPy from the Python Package Index (PyPI).

Using conda (Part of the Anaconda Distribution)

Section titled “Using conda (Part of the Anaconda Distribution)”

If you are using the Anaconda Python distribution (popular for data science), it comes pre-installed with NumPy and many other scientific libraries. However, you can install or update NumPy using conda:

conda install numpy

Or to update to the latest version available in the Anaconda channels:

conda update numpy

Anaconda (from anaconda.com) is a highly recommended free Python distribution for scientific computing, available for Windows, macOS, and Linux. It simplifies package management and environment handling.

You can often install NumPy using your Linux distribution’s package manager, although the version might be slightly older than the one available via pip or conda.

For Debian/Ubuntu:

sudo apt-get update
sudo apt-get install python3-numpy # Use python3-numpy for Python 3

For Fedora:

sudo dnf install numpy # Or python3-numpy depending on distro version

Note: Installing the full scientific stack often involves installing related packages like scipy, matplotlib, pandas, etc.

Building NumPy from source is generally for advanced users or developers needing the absolute latest changes or specific build configurations. It requires a C compiler (like GCC or Clang) and Python development headers.

Instructions can be found in the official NumPy documentation (numpy.org/install/).

To check if NumPy is installed correctly, open a Python interpreter (type python or python3 in your terminal) or use an IDE/Jupyter notebook and try to import it:

import numpy

If no error message appears, the installation was successful. If you see an ImportError or ModuleNotFoundError, there was a problem with the installation or your Python environment setup.

# Example of an error if NumPy is not installed
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'

The standard convention for importing NumPy is to use the alias np:

import numpy as np
# You can now use np to access NumPy functions, e.g.:
my_array = np.array([1, 2, 3])
print(my_array)