Tip
This page assumes you are comfortable using a terminal and are familiar with package managers.
The only prerequisite for installing NumPy is Python itself. If you don’t have
Python yet and want the simplest way to get started, we recommend you use the
Anaconda Distribution — it includes
Python, NumPy, and many other commonly used packages for scientific computing
and data science.
The recommended method of installing NumPy depends on your preferred workflow. Below, we break down the installation methods into the following categories:
- Project-based (e.g., uv, pixi) (recommended for new users)
- Environment-based (e.g., pip, conda) (the traditional workflow)
- System package managers (not recommended for most users)
- Building from source (for advanced users and development purposes)
Choose the method that best suits your needs. If you’re unsure, start with the Environment-based method using conda
or pip
.
Below are the different methods for installing NumPy. Click on the tabs to explore each method:
Recommended for new users who want a streamlined workflow.
-
uv: A modern Python package manager designed for speed and simplicity.
-
pixi: A cross-platform package manager for Python and other languages.
The two main tools that install Python packages are pip
and conda
. Their functionality partially overlaps (e.g. both can install numpy
), however, they can also work together. We’ll discuss the major differences between pip and conda here — this is important to understand if you want to manage packages effectively.
The first difference is that conda is cross-language and it can install Python, while pip is installed for a particular Python on your system and installs other packages to that same Python install only. This also means conda can install non-Python libraries and tools you may need (e.g. compilers, CUDA, HDF5), while pip can’t.
The second difference is that pip installs from the Python Packaging Index (PyPI), while conda installs from its own channels (typically “defaults” or “conda-forge”). PyPI is the largest collection of packages by far, however, all popular packages are available for conda as well.
The third difference is that conda is an integrated solution for managing packages, dependencies and environments, while with pip you may need another tool (there are many!) for dealing with environments or complex dependencies.
- Conda: If you use conda, you can install NumPy from the defaults or conda-forge channels:
conda create -n my-env conda activate my-env conda install numpy
- Pip:
Tip
Tip: Use a virtual environment for better dependency management
python -m venv my-env
source my-env/bin/activate # macOS/Linux
my-env\Scripts\activate # Windows
pip install numpy
Not recommended for most users, but available for convenience.
macOS (Homebrew):
Linux (APT):
sudo apt install python3-numpy
Windows (Chocolatey):
For advanced users and developers who want to customize or debug NumPy.
A word of warning: building Numpy from source can be a nontrivial exercise.
We recommend using binaries instead if those are available for your platform via one of the above methods.
For details on how to build from source, see the building from source guide in the Numpy docs.
Verifying the Installation#
After installing NumPy, verify the installation by running the following in a Python shell or script:
import numpy as np
print(np.__version__)
This should print the installed version of NumPy without errors.
Troubleshooting#
If your installation fails with the message below, see Troubleshooting
ImportError.
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy c-extensions failed. This error can happen for different reasons, often due to issues with your setup.
Last Updated :
09 Jun, 2024
Python NumPy is a general-purpose array processing package that provides tools for handling n-dimensional arrays. It provides various computing tools such as comprehensive mathematical functions, and linear algebra routines. NumPy provides both the flexibility of Python and the speed of well-optimized compiled C code. Its easy-to-use syntax makes it highly accessible and productive for programmers from any background. In this article, we will see how to install NumPy as well as how to import Numpy in Python.
Pre-requisites:
- Python
- PIP or Conda (depending upon user preference)
Installing Numpy on Windows
Below are the ways by which we can install NumPy on Windows and later on import Numpy in Python:
- Using Conda
- Using PIP
Install Numpy Using Conda
If you want the installation to be done through conda, you can use the below command:
conda install -c anaconda numpy
You will get a similar message once the installation is complete
Make sure you follow the best practices for installation using conda as:
- Use an environment for installation rather than in the base environment using the below command:
conda create -n my-env
conda activate my-env
Note: If your preferred method of installation is conda-forge, use the below command:
conda config --env --add channels conda-forge
Installing Numpy For PIP Users
Users who prefer to use pip can use the below command to install NumPy:
pip install numpy
You will get a similar message once the installation is complete:
Now that we have installed Numpy successfully in our system, let’s take a look at few simple examples.
Example of Numpy
In this example, a 2D NumPy array named arr
is created, and its characteristics are demonstrated: the array type, number of dimensions (2), shape (2 rows, 3 columns), size (6 elements), and the data type of its elements (int64).
Python
# Python program to demonstrate # basic array characteristics import numpy as np # Creating array object arr = np.array( [[ 1, 2, 3], [ 4, 2, 5]] ) # Printing type of arr object print("Array is of type: ", type(arr)) # Printing array dimensions (axes) print("No. of dimensions: ", arr.ndim) # Printing shape of array print("Shape of array: ", arr.shape) # Printing size (total number of elements) of array print("Size of array: ", arr.size) # Printing type of elements in array print("Array stores elements of type: ", arr.dtype)
Output:
Array is of type:
No. of dimensions: 2
Shape of array: (2, 3)
Size of array: 6
Array stores elements of type: int64
NumPy (Numerical Python) is a powerful Python library for numerical computing. The library supports working with arrays, matrices, and various mathematical functions. NumPy is used for scientific computing, engineering, data science, and machine learning projects.
This guide shows how to install NumPy on various systems using different methods.
Prerequisites
- Access to the terminal.
- Python 3 installed and added to PATH.
- Either Conda or PIP installed for package management.
Note: This guide uses Ubuntu 22.04. The installation steps are similar accross different operating systems (Linux, macOS, and Windows). Windows users use the command prompt instead of the terminal and require administrator privileges to perform any installation.
How to Install NumPy via Terminal
The simplest way to install NumPy is via the terminal. Depending on the system requirements, you can use PIP or Conda to install the library.
The sections below show how to install it using both methods.
Install NumPy with PIP
To install NumPy using PIP, follow the steps below:
1. Open the terminal window.
2. Check if PIP is installed. Run the following command:
pip --version
The command shows the PIP version if the package manager is installed. If the version number does not show, run the following command to install PIP:
python -m ensurepip
The command automatically runs a PIP installation script. Alternatively, see one of our OS-specific installation guides:
- Install PIP on Ubuntu.
- Install PIP on Debian 12.
- Install PIP on Windows.
- Install PIP on macOS.
3. Use PIP to install NumPy. Run the following command:
pip install numpy
Wait for the installation to complete.
Note: This method installs NumPy globally. You can also use PIP to install NumPy inside a virtual environment or a Conda environment.
4. Test the installation with the following example code:
python3 -c "import numpy; print(numpy.__version__)"
The command runs the Python code in quotation marks. If the installation succeeds, the code imports the library and prints the NumPy version.
Install NumPy Using Conda
When using Conda to manage Python libraries, follow the steps below to install NumPy:
1. Open the terminal.
2. Check that Conda is installed:
conda --version
The command prints the Conda version. If not, download and install Anaconda or Miniconda.
3. Create a Conda environment:
conda create -n [environment_name]
Replace [environment_name]
with the actual environment name. Enter y when prompted to proceed.
Note: The installation does not require creating an evnironment, but it’s considered best practice to isolate Python projects for simpler dependency management.
4. Activate the environment with:
conda activate [environment_name]
Use the environment name from the previous step. The terminal window changes to the environment.
5. Install NumPy with the following command:
conda install numpy
Enter y to confirm the installation when prompted.
6. Test the installation with:
python3 -c "import numpy; print(numpy.__version__)"
The command runs Python code that imports the NumPy library and prints the version number.
Build NumPy From Source
An advanced way to install NumPy is to build it from source. The method is meant for users with specific requirements and developers looking to contribute to the project.
Follow the steps below to build NumPy from source:
1. Clone the NumPy Git repository locally:
git clone https://github.com/numpy/numpy.git
The command clones the project into the numpy directory.
2. Navigate to the project directory:
cd numpy
3. Initialize and update submodules with git submodule update:
git submodule update --init
After this step, the submodule directories are fully functional.
4. Install the NumPy package from the current directory with:
pip install .
Wait for the installation to complete.
5. Navigate to the home directory, as running Python code from the installation directory will not work.
cd ..
Alternatively, navigate to your project directory or any other location.
6. Test the NumPy installation:
python3 -c "import numpy; print(numpy.__version__)"
The command prints the NumPy dev version, indicating a successful installation.
How to Update NumPy
Update NumPy with PIP or Conda depending on the Python environment setup. See the examples below:
- PIP:
pip install --upgrade numpy
- Conda:
conda update numpy
Choose a method that best aligns with your current environment and NumPy installation method.
Conclusion
This guide showed how to install NumPy on your system using two different methods: PIP and Conda.
Next, check out our introduction to Python Pandas. It is an open-source Python library built on top of NumPy and primarily used for data analysis.
Was this article helpful?
YesNo
NumPy is a Python library that stands for Numerical Python. It is widely used for performing numerical computations and provides support for large, multi-dimensional arrays and matrices. In addition to this, it offers a variety of mathematical functions to operate on these arrays efficiently. NumPy is commonly utilized by developers in areas like scientific computing, engineering, data science, and machine learning.
In this tutorial, we’ll demonstrate how to install NumPy using Python on Windows and Linux operating systems.
Installing NumPy Using Python on Windows
To install NumPy on Windows, first install Python and ensure it’s added to the PATH, confirm that pip is installed, and then use it to install NumPy. Finally, confirm the installation by checking NumPy’s version in the Python interpreter.
Let’s go through the following steps to learn how to install NumPy Python on Windows:
Step 1: Install Python on Widows
Visit the official Python website to download the latest Python version for your Windows system. After downloading, find the installer file and click the ‘Install’ button to begin the Python installation. Be sure to select the option to add Python to the PATH. Read our dedicated guide to learn more about installing Python on Windows.
You can check the Python version by executing the command below:
python --version
Step 2: Install Pip
Next, make sure pip for Python is installed on your Windows system. Pip is generally installed with Python. You can confirm its installation by running the following command:
pip --version
Step 3: Install NumPy Python Windows
Once Python and pip are successfully installed on your system, execute the command below to install NumPy on Windows:
pip install numpy
Step 4: Verify the NumPy Installation on Windows
Finally, you can confirm the NumPy installation on Windows by checking its version. For this purpose, first, open a Python interpreter by typing python in the CMD and then execute the following script:
import numpy print(numpy.__version__)
The output confirms that numpy 2.1.3 has been successfully installed on our system.
Install NumPy with our Python Hosting!
Set up NumPy effortlessly using our optimized Python hosting, designed for seamless integration and exceptional performance in numerical computing.
Installing NumPy Using Python on Linux
NumPy is a commonly used Python library to perform numerical computations. You can follow the below-listed steps to install it on Linux using Python:
Step 1: Install Python
On most modern Linux distributions Python comes preinstalled. You can verify it by executing the following command in the terminal:
python3 --version
In case, Python is not installed on your Linux system, you can install it by running the following command:
sudo apt install python3
Step 2: Install Pip
After installing Python, make sure Pip is also installed on your system:
pip3 --version
If pip is not installed on your Linux system, you must read our dedicated guide on how to install pip on Windows and Linux.
Step 3: Install NumPy Python Linux
After pip is successfully installed, use it to install NumPy by running the following command:
pip3 install numpy
Alternatively, you can use a trusted PyPI mirror to install NumPy using Python on Linux:
pip3 install numpy --index-url https://mirrors.aliyun.com/pypi/simple/
Step 4: Verify the NumPy Installation
Now type python3 in the terminal to open the Python interpreter. After this, execute the following script to import numpy:
import numpy
Then run the command below to show the installed version of the NumPy on Linux:
print(numpy.__version__)
The output verifies that NumPy has been successfully installed on Linux:
This is how you can install NumPy using Python on Windows and Linux operating systems.
Conclusion
NumPy is a robust Python library designed for numerical calculations, offering support for large, multi-dimensional arrays and matrices, along with a range of mathematical functions. In this article, we discussed how to install NumPy on both Windows and Linux. On Windows, we covered installing Python, ensuring pip is set up, and using it to install NumPy. For Linux, we followed similar steps to verify Python and pip installations before installing NumPy via the terminal. These steps enable you to set up NumPy on your system and start using it for efficient numerical tasks.
Unlock high-performance computing with Ultahost’s high-speed Virtual Dedicated Servers, perfect for running Python libraries like NumPy. With customizable resources, Ultahost ensures seamless installation and optimal performance for your numerical computing projects.
FAQ
What is NumPy?
NumPy is a Python package designed for numerical analysis. It enables us to handle large, multi-dimensional arrays and matrices and provides an extensive set of mathematical functions for efficient array operations.
How do I install Python on Windows for NumPy?
To install Python on Windows, download the installer from the official Python website and make sure to check the option to add Python to the system PATH during installation.
How can I check if Python is installed on Windows?
You can check the Python version installed on your Windows system by running the python –version command in Command Prompt.
How do I install pip on Windows?
Pip is generally installed along with Python. To confirm if pip is installed, run the command pip –version. If pip is missing, you can install it using the get-pip.py script from the official website.
How do I install NumPy on Windows?
After installing Python and pip, you can install NumPy on Windows by running the pip install numpy command in Command Prompt.
How do I verify that NumPy is installed correctly on Windows?
To verify the installation, open the Python interpreter and execute import numpy to import numpy library and print(numpy.__version__) to display the installed version of NumPy.
How do I install NumPy on Linux?
After installing Python and pip, run the command pip3 install numpy to install NumPy on a Linux system.
NumPy is a powerful library for numerical computations in Python. It is widely used for mathematical operations, data analysis, and scientific computing. This guide will walk you through the steps to install NumPy in Python, whether you are using Windows, macOS, or Linux.
Prerequisites
Before installing NumPy, make sure you have Python installed on your system. You can check the Python version using the following command:
python --version
If Python is not installed, download and install it from the official Python website.
Installing NumPy Using Pip
The easiest way to install NumPy is by using pip, Python’s package manager. Run the following command in your terminal or command prompt:
pip install numpy
This command will download and install the latest version of NumPy. If you are using Python 3, you might need to use:
pip3 install numpy
Verifying the Installation
To confirm that NumPy is installed correctly, open a Python shell and run:
import numpy
print(numpy.__version__)
This should display the version of NumPy that you have installed.
Installing NumPy in a Virtual Environment
It is a good practice to use a virtual environment when working with Python projects to avoid conflicts between different packages. To install NumPy in a virtual environment, follow these steps:
- Create a virtual environment:
python -m venv myenv
- Activate the virtual environment:
- On Windows:
myenv\Scripts\activate
- On macOS/Linux:
source myenv/bin/activate
- On Windows:
- Install NumPy within the virtual environment:
pip install numpy
This will keep your NumPy installation isolated from other projects.
Troubleshooting Installation Issues
If you encounter the error ModuleNotFoundError: No module named ‘numpy’, it means that Python cannot find the NumPy library. Make sure that NumPy is installed in the correct environment or virtual environment.
For a detailed solution to this error, check out our article: [Solved] ModuleNotFoundError: No module named ‘numpy’.
Installing NumPy with Anaconda
If you are using Anaconda, you can install NumPy using the following command:
conda install numpy
Anaconda will handle the dependencies and ensure that NumPy is installed properly.
Conclusion
Installing NumPy in Python is a simple process, whether you use pip, a virtual environment, or Anaconda. With NumPy installed, you can start performing advanced mathematical operations and data analysis in Python. If you face any issues, make sure to verify your installation and refer to the troubleshooting guide.