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
(
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):
- 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, specially provided for Spyder IDE and other tools, suitable for scientific computing development.
- WinPython: another free Python distribution, containing scientific computing packages and the Spyder IDE. Supports Windows.
- Pyzo: a free distribution based on Anaconda and the IEP interactive development environment, ultra-lightweight. Supports Linux, Windows, and Mac systems.