NumPy Installation
The official Python distribution does not include the NumPy module.
We can use the following methods to install it.
1. Using Existing Distributions
For many users, especially on Windows, the easiest method is to download one of the following Python distributions, which include all the key packages (including NumPy, SciPy, matplotlib, IPython, SymPy, and other packages that come with the Python core):
Anaconda: A free Python distribution for large-scale data processing, predictive analytics, and scientific computing, dedicated to simplifying package management and deployment. Supports Linux, Windows, and Mac systems.
Enthought Canopy: Offers both free and commercial distributions. Supports Linux, Windows, and Mac systems.
Python(x,y): A free Python distribution that includes the complete Python language development kit and Spyder IDE. Supports Windows, limited to Python 2.
WinPython: Another free Python distribution that includes scientific computing packages and 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.
2. Installing with pip
The simplest way to install NumPy is to use the pip tool:
pip3 install --user numpy scipy matplotlib
The --user
option ensures that the installation is limited to the current user, rather than being written to the system directory.
By default, the installation uses a foreign route, which is too slow. We can use Tsinghua's mirror:
pip3 install numpy scipy matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
Installation on Linux
Ubuntu & Debian
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
CentOS/Fedora
sudo dnf install numpy scipy python-matplotlib ipython python-pandas sympy python-nose atlas-devel
Mac System
The Homebrew package for Mac systems does not include NumPy or other scientific computing packages, so you can install them using the following method:
pip3 install numpy scipy matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
Installation Verification
To test if the installation was successful:
>>> from numpy import *
>>> eye(4)
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
from numpy import * imports the numpy library.
eye(4) generates a diagonal matrix.