Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

NumPy Installation

NumPy Installation

The distribution on the Python official website does not include the NumPy module.

We can use the following methods to install.


Install using pip

The easiest way to install NumPy is to use the pip tool:

pip3 install numpy

Python3 is used here; if you use Python2, you can install it with pip install numpy.

By default, a foreign route is used, which is too slow; we can use the Tsinghua mirror:

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


Install using conda

If you are using an 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, you can refer to:Anaconda Tutorial。


Install from Source

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



python setup.py install


Installation verification

After installation by any method, 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, the correct version number information will be output:

1.26.4


Use an existing distribution

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