How to install Pip on Ubuntu

Are you a Python developer? If yes, then you have probably come across the Pip utility. Pip is a Python command line tool that allows you to download, install and manage Python packages on your system. Think of it as NPM or YARN, which Javascript developers use to manage NodeJS packages.

This post will provide a comprehensive guide on installing pip for Python2 and Python3 on Ubuntu 20.04 LTS. The steps described in this post will also work for Ubuntu 16.04 LTS and other newer releases.

Why pip2 and pip3?

You might be wondering why there are different versions of pip? That’s because there are currently two Python flavors in the tech industry – Python2 and Python3. As the names suggest, pip2 is used for managing Python2 packages while pip3 is used to manage Python3 packages.

Although pip works well in managing packages; when installing a Python module globally, it’s highly recommended to use the Ubuntu apt package manager. However, that will also depend if the package is available in the Ubuntu repository. These packages are developed and tested to work well in Ubuntu systems.

Installing packages with pip is recommended when working with Python virtual environments. Virtual environments allow you to install a package inside an isolated environment. That way, you don’t have to worry about conflicting packages from other projects breaking your application or program.

Note: Since the release of Ubuntu 20.04 LTS, the only Python version that comes pre-installed is Python3.

Installing pip for Python3

Launch the Terminal and execute the commands below to install pip for Python3 on your Ubuntu system.

sudo apt update
sudo apt install python3-pip

The command above will download and install pip3 on your system. When done, run the command below to verify the installation.

pip3 --version

You should see an output similar to the image below, although the release version might be different.

pip3 version
Pip3 version

Installing pip for Python2

Before installing pip for Python2, you first need t install Python2 on your system as it doesn’t come pre-installed on Ubuntu 20.04 or newer releases. Follow the steps below.

Since pip for Python2 is unavailable in the Ubuntu 20.04 LTS repositories, we will use the get-pip.py script to install it on our system.

Follow the steps below.

You should see an output similar to the image below.

pip2 version
pip2 version

How to use pip

Tip: This post will give examples using pip3 since we have only Python3 installed.

This section will give you a list of helpful pip commands to download and install packages from PyPI. One of the basic commands you can use is the --help command which lists all the available commands you can use with pip.

pip3 --help
pip3 help command
pip3 help command

Use the command syntax below to view the various options available for each command.

pip3 [command] --helpe.g

pip3 install --help

pip3 command options
pip3 command options

Install packages with pip

As an example, this post will install Scapy – a Python package used to create, forge and decode network packets. However, you can use the command syntax to install any other package of your choice.

pip3 install [package-name]
e.gpip3 install scapy

install scapy
Install scapy

Install a specific version of a package with pip

There are situations where you might want to install a specific version of a package. Luckily, pip has provision for that feature. Use the syntax below.

pip3 install [package-name]==[version-number]e.g
pip3 install scapy==2.4.5

Install packages using the requirements.txt File

When you download a Python project from a platform like GitHub, you will notice that it comes with a requirements.txt file containing a list of all Python modules required to run the project. You can easily install all these packages with pip using the command below.

pip3 install -r requirements.txt

List all Installed Packages with pip

If you want to keep track of all the packages you have installed with pip, you can easily do so using the command below.

pip3 list
list pip3 packages
List pip3 packages

Upgrade a package with pip

If you want to install an update of an already installed package, you can easily do so using the command below.

pip3 install --upgrade [package-name]e.g
pip3 install --upgrade scapy
upgrade a pip package
Upgrade a pip package

Uninstall a package

To uninstall any package installed using pip, execute the command below.

pip3 uninstall [package-name]e.g
pip3 uninstall scapy
uninstall a package with pip
Uninstall a package with pip

Conclusion

This post has given you a comprehensive guide on installing and working with pip on your Ubuntu system. It has shown you:

  • How to install pip for Python2
  • How to install pip for Python3
  • How to install, manage, upgrade, and uninstall packages with pip

Did you come across any issues, or do you have any comments regarding this post? Don’t hesitate to let us know in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Server Status

Aradippou Chat Larnaca Nicosia

Chat Links

Official Links.

Chat.

Alternative Mirror Links.

1. KiwiIRC 1.
2. KiwiIRC 2.

Other Web Clients.

1. IrcCloud.

Recent Posts

Related Posts:

Archives

Follow me on Mastodon

Super Club Radio

Mighty Deals

CyIRC

CyIRC Tweets