How to Install Python Pip on Ubuntu 20.04

PIP is the standard package manager for installing Python packages. With PIP, you can list, search and download to install packages from the Python Package Index (PyPI). PIP was first included with the Python installer since version 3.4 for Python 3 release and 2.7.9 for Python 2 and is well utilized with many Python projects.

In the following tutorial, you will learn how to install the PIP2 or PIP3 Ubuntu 20.04 system.

Advertisement

Prerequisites

  • Recommended OS: Ubuntu 20.04 – optional
  • User account: A user account with sudo or root access.
  • Required Packages: Python2 or Python3.

Update Operating System

Update your Ubuntu operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@ubuntu ~]$ sudo whoami
root

 To set up an existing or new sudo account, visit our tutorial on adding a User to Sudoers on Ubuntu.

To use the root account, use the following command with the root password to log in.

su

PIP2 vs PIP3

For those new to the python programming language altogether, you may wonder what the difference between PIP2 and PIP3 is. To sum it up, PIP2 is a soft link for a particular installer running an older python version. PIP3 is an updated version of pip which is used basically for python 3+.

It is highly recommended to use Python 3 and PIP3, and you should be upgrading to this as soon as possible.

Advertisement

PIP2 OR PIP3 VS APT Package Manager

A question that is asked regularly should I use APT or PIP. This is a choice that every user must make. APT is faster however is more outdated where PIP is used to download and install packages directly from PyPI. For those unaware, PyPI is hosted by Python Software Foundation, a package manager that only deals with python packages that are often more updated than those hosted by Canonical through APT. The only drawback of using PIP through PyPI is that the packages can take longer to install.

Advertisement

Install Python 2 or 3 on Ubuntu 20.04

Install Python 2

By default, Ubuntu has Python2, which can be installed with either the python or python2 command.

To install Python2, which will use PIP2 later on, use the following command:

sudo apt install python -y

Next, proceed to the Install PIP and install the corresponding version to your Python installation.

Install Python 3

To install Python 3, which will use PIP3 later on, use the following:

sudo apt install python3 -y

Next, proceed to the Install PIP and install the corresponding version to your Python installation.

Install PIP 2 or 3 on Ubuntu 20.04

Install PIP2

To install PIP on Ubuntu 20.04, you will need to make sure the Universe repository is installed and enabled:

sudo add-apt-repository universe -y && sudo apt update

To install PIP2, you will need to download the .py script as follows:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py

Now execute the .py script:

sudo python2 get-pip.py

Example output of dependencies that will be installed:

How to Install Python Pip onUbuntu 20.04

Type Y, then press the enter key to continue the installation.

To confirm if PIP2 was installed successfully, run the following version command:

pip2 --version

Example output:

pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

Install PIP3

To Install PIP3(For Python 3+):

sudo apt install python3-pip 

Example output of dependencies that will be installed:

How to Install Python Pip onUbuntu 20.04

To confirm if PIP3 was installed successfully, run the following version command:

pip3 --version 

Example output:

spip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

How to Use PIP on Ubuntu 20.04

PIP has quite an extensive list of packages that can be installed, an easy way to see some of what is available is to run the PIP command list and search. The commands will work on both PIP and PIP3 with a slight adjustment, of course.

The tutorial will use some examples below for PIP3.

First off, to view a list of all pip commands and options, type the following command:

pip3 --help
How to Install Python Pip onUbuntu 20.04

Example of using pip3 help, example below on getting help on download:

pip3 download --help

Example output:

How to Install Python Pip onUbuntu 20.04

To list packages that are available to install on PIP3, use the following:

pip3 list

Example output:

How to Install Python Pip onUbuntu 20.04

If you want to narrow down the list, use the search feature as follows:

pip3 search PACKAGE_NAME

To install a package using PIP3, use the following command:

sudo pip3 install numpy

In the above example, the NumPy package was installed.

Example output:

How to Install Python Pip onUbuntu 20.04

To remove a PIP3 package, use the following command:

sudo pip3 uninstall numpy

Example output:

How to Install Python Pip onUbuntu 20.04

Type Y, then press enter key to complete the uninstallation.

Example output:

Successfully uninstalled numpy-1.21.2

How to Uninstall PIP on Ubuntu 20.04

To remove PIP from your Ubuntu system, follow the below commands depending on which version you have installed.

To remove PIP:

sudo python -m pip uninstall pip

Example output:

How to Install Python Pip onUbuntu 20.04

Type Y, then press ENTER KEY to complete the uninstallation.

Example output:

Successfully uninstalled pip-20.3.4

To remove PIP3:

sudo apt autoremove python3-pip

Example output:

How to Install Python Pip onUbuntu 20.04

Type Y, then press ENTER KEY to complete the uninstallation.

Comments and Conclusion

In the tutorial, you have learned how to install PIP for Python or Python 3 and search, install, and remove packages.

To find out further information on PIP, visit the official documentation.

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
adplus-dvertising
0
Would love your thoughts, please comment.x
()
x