Numpy is the Python library which is highly popular in the field of data science and for controlling numerical data in Python programming. To manage Python libraries/packages, a pip package manager is used. This write-up will demonstrate the possible ways to install NumPy on Ubuntu 22.04.
The content of this write-up is:
- Prerequisite: Install Python and Pip
- Method 1: How to Install NumPy Python 3 on Ubuntu 22.04?
- Method 2: How to Install NumPy Python 2 on Ubuntu 22.04?
- How to Upgrade NumPy in Ubuntu 22.04?
- How to Remove Numpy in Ubuntu 22.04?
Prerequisite: Install Python and Pip
First, update the packages and ensure that all packages are up to date. To do so, run the following command:
$ sudo apt update
Python 3 is pre-installed on Ubuntu 22.04, to verify it, you can use the following command:
$ python3 --version
To use Python in Ubuntu, install the pip for Python3 using the command:
$ sudo apt install python3-pip
Once pip3 is installed, verify and check the version of pip using the given command:
$ pip3 --version
Now, let’s move toward the installation of NumPy on Ubuntu 22.04.
Method 1: How to Install NumPy Python 3 on Ubuntu 22.04?
In Ubuntu 22.04, NumPy is automatically pre-installed while installing pip. However, if it is not installed, execute the following command:
$ sudo apt install python3-numpy
In our scenario, NumPy packages were automatically installed during the installation of pip.
Now, to access the python shell just type python3 in the terminal:
$ python3
To check if NumPy is installed, check the version of NumPy in Python shell using following command:
import numpy
numpy.version.version
The above output represents that NumPy version 1.23.4 is installed.
Method 2: How to Install NumPy Python 2 on Ubuntu 22.04?
To install python2 on ubuntu 22.04 go to the python2 installation article.
Once the python2 is installed, verify and check the version of pip using the given command:
$ pip2 --version
Now, to install NumPy on python2 execute the following command;
$ pip install numpy
Numpy has been installed in the Ubuntu operating system.
Now, to access the python 2 shell just type the python2 in the terminal:
$ python2
To check if NumPy is installed, check the version of NumPy in Python2 shell using given commands:
>>> import numpy
>>> numpy.version.version
The above image represents that NumPy version 1.16.6 is installed.
How to Upgrade NumPy on Ubuntu 22.04?
If NumPy is already installed on the system. It is recommended to upgrade the installed version of NumPy as follows:
$ pip3 install --upgrade numpy
The above output shows that upgraded NumPy is installed.
How to Remove Numpy on Ubuntu 22.04?
To remove NumPy from Ubuntu, execute the following command:
$ pip3 uninstall numpy
That’s it from this guide.
Conclusion
To install NumPy, first install the pip using “sudo apt install python3-pip” command to manage the python packages, this command installs the pip as well as NumPy. if NumPy is not installed then “sudo apt install python3-numpy” can be used to install it. This article has demonstrated the method to install Numpy in Ubuntu 22.04. Apart from that, the upgrading and removal method for Numpy has also been illustrated in this post.