Home » Ubuntu » How to Install NumPy on Ubuntu 20.04

How to Install NumPy on Ubuntu 20.04

NumPy is a python library used for scientific computing. It offers the followings and much more.

  • multidimensional array object
  • masked arrays and matrices
  • shape manipulation
  • sorting
  • selecting
  • discrete Fourier transforms
  • basic linear algebra
  • basic statistical operations
  • random simulation

In this tutorial we learn how to install NumPy on Ubuntu 20.04.

Install pip on Ubuntu

Pip is the official tool for managing python packages. It helps to install, uninstall and upgrade a specific package to the latest version. Developers find this utility very useful when it comes to installing the whole package dependencies of a project.

Download pip for python 2 using wget command:

$ wget https://bootstrap.pypa.io/2.7/get-pip.py -O get-pip27.py

Now to Install pip run the following command:

$ sudo python2 get-pip27.py

As for the installation of pip for python3, the process is the same.

Download the script for pip:

$ wget https://bootstrap.pypa.io/get-pip.py -O get-pip.py

To Install pip for python 3, type:

$ sudo python3.9 get-pip.py

Install NumPy on Ubuntu

The pip utility helps to install NumPy for both versions of python. As for the python 2.x version, the following command installs the NumPy package.

$ python2 -m pip install numpy

The -m option helps to use a specific python package; in our case pip.

On success, the following should be displayed on your console.

Collecting numpy
   Downloading numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
      |████████████████████████████████| 17.0 MB 12.2 MB/s 
 Installing collected packages: numpy
   WARNING: The scripts f2py, f2py2 and f2py2.7 are installed in '/home/linoxide/.local/bin' which is not on PATH.
   Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
 Successfully installed numpy-1.16.6

For the installation of numpy on python 3, run the following command.

$ python3.9 -m pip install numpy

Verify the installation.

$ python3.9 -m pip show numpy

The option show helps to identify an installed python package.

numpy package for python3
$ python2 -m pip show numpy

Import numpy from the python interactive shell

The following command imports the library under the name of np. It works both for python 2 and python 3.

import numpy as np
import numpy library
Import numpy

Upgrade NumPy to the latest version

The pip utility has an option that helps to upgrade an installed package to the latest
version.

To upgrade numpy for python 2, type:

$ pip2 install --upgrade numpy

For python 3 run the following command:

$ pip3 install --upgrade numpy

Final thoughts

Through this article, you learned how to properly install the numpy package for both python 2 and python 3. You also learned how to upgrade the numpy package to the latest version.

2 Comments... add one

    • That will install a pre-compiled binary package, which could be a slightly older version. Installation via pip help to get newer files and optimized with compilation flags.

      Reply

Leave a Comment