Install Python packages using PIP in Ubuntu

We can install Python packages, not available in standard Ubuntu repository, using PIP. PIP is a command-line tool for managing Python packages. When we install a package through PIP, it installs all the associated dependencies thus preventing partial installs. In this article, we would discuss how to install Python packages using PIP in Ubuntu.

Furthermore, there are two versions of PIP available – PIP and PIP3. Both the packages provide similar functionality except they are available for different versions of Python. So, if you want to install packages for version 2 of Python then go for PIP. For Python 3 packages, PIP3 should be considered.

Install Python packages using PIP

To ensure you have the right version of PIP installed. This could be identified through the command –

pip --version

or,

pip3 --version

In case you don’t have PIP package installed, then refer the article – Install PIP in Ubuntu 19.10.

Moving forward, we would discuss various operations which could be performed using the tool PIP3. You could replace PIP3 with PIP if you choose to go with version 2 of Python.

To list installed packages

pip3 list

To show information about the package –

pip3 show <package_name>

for instance,

pip3 show wheel

To search PyPI (Python Package Index) for a package –

pip3 search <package_name>

for instance,

pip3 search numpy

To install a package –

pip3 install <package_name>

for instance,

pip3 install numpy

To remove a package –

pip3 uninstall <package_name>

for instance,

pip3 uninstall numpy

Furthermore, you may want to install a specific version of package which could be compatible with other packages installed. Doing so would require you to issue the following in terminal –

pip3 install "package_name==package_version"

for instance,

pip3 install "numpy==1.17.2"

To upgrade already installed package –

pip3 install --upgrade <package_name>

for instance,

pip3 install --upgrade numpy

To specify a target directory for the package –

pip3 install -t /path/of/package/ <package_name>

for instance,

pip3 install -t /home/<user_name>/Downloads/ numpy

Lastly, install the package itself and ignore its dependencies

pip3 install --no-deps <package_name>

for instance,

pip3 install --no-deps numpy

Note: You can choose to ignore dependencies on a case-by-case basis. If you don’t know what you are doing then it is best to install the package as it is. Otherwise, you may get a broken package.

In conclusion, we have discussed a few options which are associated with the Python packages installation process with the help of an example.

Additional Info –

In case you encounter a warning during installation of a Python package –

The scripts f2py, f2py3 and f2py3.7 are installed in '/home/<user_name>/.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.

It states that above mentioned scripts have been installed but the directory in which they are installed is not considered a PATH. Therefore, open a text editor and append ~/.bashrc file with the following –

export PATH=/home/<user_name>/.local/bin:$PATH

or, if you want to go ahead without making any changes to ~/.bashrc file then use –no-warn-script-location option while installing Python packages.

Similar Posts