How to Install pip on Ubuntu

In this guide, we will show you how to install the Python package manager called pip on Ubuntu.

Ubuntu Install pip

pip is the go-to package manager for the Python programming language.

The package manager allows you to install additional Python packages and modules with ease.

You can also use pip to update the existing Python packages on your Ubuntu system with a single command.

In the next few steps, we will show you how to install pip to your Ubuntu system.

You will also see how you can use pip to install and remove Python packages with ease.

We won’t be touching on installing pip for Python 2 as it has been marked that it is at the end of its life since the start of 2020.

Before proceeding, you will, of course, need to have Python installed on your system. We have a guide that will show you how to install Python on Linux.

Installing pip on Ubuntu for Python 3

Installing pip for Python 3 is a straightforward process on Ubuntu as it is available through the package repository.

In just a couple of steps, we will have the package manager installed, and you will be able to put it to use

1. To start, we should update the package list on our Ubuntu device.

Additionally, we will also upgrade any currently installed package.

sudo apt update
sudo apt full-upgrade

2. Once the update has been completed, we can install pip for Python 3 to Ubuntu.

To install pip, all we need to do is run the following command on your device.

sudo apt install python3-pip

3. We can verify that pip for Python 3 is installed successfully.

The easiest way to do this is to get pip to output its installed version.

pip3 --version

From this command, you should see something like below appear in the command line.

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

Using pip to Install a Python Package

With pip now installed on Ubuntu, we can now put this Python package manager to use.

In this section, we will show you how easy it is to install a package using pip.

Syntax for Installing using pip

The basic syntax for using pip on Ubuntu is straightforward and easy to remember.

As we are using Python 3, we will be able to use pip by using “pip3” in the terminal.

We then need to follow pip3, followed by “install“, then the name of the package you want to install.

pip3 install [PACKAGENAME]

By default, this package will need to be available through the Python Package Index called PyPI to be installed using this command.

Example of Using pip to Install a Package

To show you this in action, we will be using pip on our Ubuntu system to install the requests package.

This package is a popular one as it allows us to make HTTP requests from Python.

1. To install this Python package on Ubuntu using pip, all we need to do is run the following command.

As you can see, we reference pip3, followed by “install“, then the name of the package we are installing.

That package name in our case is called “requests“.

pip3 install requests

Upon running this command, pip will communicate with the PyPI service to see if the package exists.

If the package is available, it will download it and make it available to Python.

2. Once the installation has finished, you can now use the installed Python package in your application.

Using pip to Uninstall a Package on Ubuntu

You can also use pip to uninstall Python packages from Ubuntu that you are no longer using.

To remove a package, all you need to know is its name.

Syntax for Uninstalling a Package with pip

Using pip to remove a Python package is a straightforward process.

All we need to do isĀ  use pip3 followed by the “uninstall” option, then the name of the package we want to uninstall.

pip3 uninstall [PACKAGENAME]

Example of Uninstalling a Package with pip

To show you how uninstalling a package on Ubuntu using pip works, we will remove the “requests” package.

1. Removing the requests Python package is as straightforward as running the following command.

You can see that we have used the “pip3 command, followed by “uninstall“, then the package name.

pip3 uninstall requests

2. When you uninstall a package, it will list all of the files pip will remove.

When asked if you would like to proceed, type in Y, then press the ENTER key.

3. If pip was successful at removing the specified package from Ubuntu, you will get a message as shown below.

Process (y/n)? y
    Successfully uninstalled requests-2.25.1

Conclusion

You should now have the Python package manager called “pip” installed on your Ubuntu system.

pip allows you to install all of the libraries you need using a simple command.

If you run into any issues with getting pip installed to Ubuntu, please leave a comment below.

If you are just getting started with Python, be sure to check out our Python tutorials. Also, check out some of our other Ubuntu guides to learn what else you can do with the system.

Leave a Reply

Your email address will not be published.