Raspberry Pi

How to Install NumPy on Raspberry Pi

NumPy or Numerical Python is an essential Python library that deals with arrays and matrices, it works for array processing and can also act as a container to store multidimensional data.  It is used to perform scientific computing and mathematical calculations like linear algebra, Fourier transform and generating random numbers. In this article, the installation of NumPy is discussed.

How to Install NumPy on Raspberry Pi

To install the NumPy Library for Python on Raspberry Pi the method is discussed below:

Step 1: Update or Upgrade the Apt Repository

To install any new package, it is always recommended to firstly update and then upgrade the repository so that the latest versions of packages can be installed from the official repository of Raspberry Pi:

To update the repository, use the below-mentioned command:

$ sudo apt update

Then after updating use the below-mentioned command to upgrade all the packages that require an upgrade:

$ sudo apt upgrade

Step 2: Installing Python and Pip

NumPy is a library of Python so before installing NumPy it is mandatory to have Python installed in Raspberry Pi and Pip is required to install the NumPy library. So, by using the below-mentioned command install both Python and pip:

$ sudo apt install python3-dev python3-pip

To verify if the installation is successful or not type the below-mentioned command:

$ python3 --version

The output of the above command will display the version of Python which is installed and if the version is displayed successfully, it means Python has been installed.

Step 3: Installing NumPy

All the requirements to install NumPy are already fulfilled so now we can finally install NumPy. To install NumPy there are two commands user can opt for any of these:

Both the commands are given below:

1: apt Command

The below-mentioned apt command is used to install NumPy from the official repository of Raspberry Pi:

$ sudo apt install python3-numpy

2: pip Command

The below-mentioned pip command will install the NumPy library directly, the advantage of using pip3 over apt command is that it will install the latest version of NumPy whereas if apt will install whatever version is available in the repository so it could be an old one.

$ sudo pip3 install numpy

Step 4: Verify the Installation

To verify the installation of the NumPy library the below-mentioned command is used:

$ pip show numpy

The output of the above command will display the version and details of NumPy, from here you can also find out if the installed version is the latest version or not.

That’s all for the installation process of NumPy on Raspberry Pi.

Conclusion

NumPy is an essential Python library that allows users to work with arrays and matrices in Python programs. To install NumPy on Raspberry Pi Python and pip need to be installed first. After that NumPy can be installed either by using the apt command or by using the pip command.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.