How to Install Numpy on Mac, Linux, and Windows
NumPy is a library for the Python language, adding the support for large, multi-dimensional arrays and matrices, along with the large collection of high-level mathematical functions. If you have installed some of the high-level packages like scikit learn or TensorFlow, or using some software like Anaconda or Jupiter notebook, then the chances are that you have already installed because by installing that software, it will automatically be installed in our system.
Now, if you have not installed any software or packages in the past, then you don’t need them. You can use standalone install the packages and use it in your Python program.
Steps to install Numpy on Mac
- The first step is to check your Python version, and according to version, you will have to install it.
- Then you will have to type the command to install Numpy.
Step 1: Check Python and install Numpy
You can check the version of Python using the following command.
I am using Python 3.8 version, and it is also a default version on my Mac.
python --version Python 3.8.2
If you have not installed the latest pip version, then check out the pip upgrade tutorial.
Now, type the following command if you have Python 3.x version.
python3 -m pip install -U numpy
After 10-15 seconds, numpy will install on your Mac.
If this did not work, try adding Python and pip full path in the commands.
To check your numpy version, you can write a few lines of code.
import numpy print(numpy.version.version)
My version is the following.
python3 app.py 1.18.3
That means, we have successfully installed Numpy on my Mac.
Install Numpy on Python 2.x version
If you are using Python 2.x, let’s say Python 2.7, then you will have to install the Numpy using the following command. In the terminal, use the pip command to install numpy package.
python -m pip install -U numpy
Once the package is installed completely, type python to get into Python prompt, notice the python version is displayed too. Use the import command to include a numpy package and use it. You can also set the alias name (shortcut) for the package like np instead of numpy.
NumPy Installation On Windows Operating System
Python is not installed by default in the Windows operating system, just like Mac does.
You can download the latest version of Python from python.org.
Once Python is installed successfully in your system, open command prompt and use pip to install numpy.
Now, type the following command to install Numpy on Windows.
pip3 install numpy
It will install Numpy, and you can check the numpy version the same as we have done in the previous section.
NumPy Installation On Linux Operating System
Python is installed by default on Linux(Ubuntu) systems. However, pip is not installed. If you need the complete package then download the Python from python.org and install it on your Ubuntu operating system using the apt install command.
Alternatively, you can install the pip on Ubuntu and then install numpy, which is the easier of the two ways.
You will need the root privileges on the system to install pip and numpy. Open the terminal in Ubuntu and install pip and pip3 using apt.
sudo apt install python-pip python-pip3
Once the pip is installed, you can install numpy library with the same commands to install Numpy.
sudo apt install python-numpy
This is the recommended approach is to install the stable Numpy module directly from the Ubuntu repository.
- # – requires given Linux commands to be executed with root privileges either directly as a root user or by use of sudo command.
- $ – requires given Linux commands to be executed as a regular non-privileged user.
Now, you can use the Numpy in Python in Linux Ubuntu systems.
Finally, How to Install Numpy on Mac, Linux, and Windows tutorial is over.