NumPy Installation

The distributions on the official Python website do not include the NumPy module.

We can install it using the following methods.


Install with pip

The easiest way to install NumPy is to usethe pip tool:

pip3 install numpy

Here we use Python 3. If you use Python 2, you can install it with `pip install numpy`.

By default, it uses an overseas source, which is too slow. We can use the Tsinghua mirror:

pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

Install with conda

If you are using the Anaconda environment, you can use conda to install NumPy:

conda install numpy

NumPy installed via conda usually comes with some optimized math libraries (such as Intel MKL), which can improve performance.

For more information about conda commands, refer to:Anaconda Tutorial。


Install from Source

If you need to install NumPy from source, you can download the source code from the official NumPy GitHub repository:https://github.com/numpy/numpy, enter the unzipped directory and execute the following commands:

python setup.py install

Verify Installation

Regardless of which method you used, after installation you can verify whether NumPy was installed successfully with the following code:

Example

import numpy as np
print(np.__version__)

If the installation is successful, it will output the correct version information:

1.26.4

Use Existing Distributions

For many users, especially on Windows, the simplest method is to download the following Python distributions, which include all the key packages (including NumPy, SciPy, matplotlib, IPython, SymPy, and other packages bundled with the Python core):

  • Anaconda: A free Python distribution for large-scale data processing, predictive analysis, and scientific computing, dedicated to simplifying package management and deployment. Supports Linux, Windows, and Mac systems.
  • Enthought Canopy: Provides free and commercial distributions. Supports Linux, Windows, and Mac systems.
  • Python(x,y): A Python distribution for scientific computing and data analysis, specifically for ... provides ... and other tools, suitable for scientific computing development work.Spyder IDE: Another free Python distribution, containing scientific computing packages and Spyder IDE. Supports Windows.
  • WinPython: A free distribution based on Anaconda and the IEP interactive development environment, ultra-lightweight. Supports Linux, Windows and Mac systems.
  • PyzoOther Extensions
AI thinking...