How to Install Python Pip on Ubuntu 20.04

install pip ubuntu

Pip stands for “Pip Installs Packages” is a package management tool used to simplifies the package installation and management process written in Python. You can search, download and install packages from the Python Package Index using the pip command easily. Pip is a cross-platform package manager that allows you to manage additional libraries and dependencies for Python project. Installing Pip on Ubuntu Linux is pretty simple & straight forward process.

In this tutorial, we will show you how to install Pip for Python 3 and Python 2 on Ubuntu 20.04 Linux. We will also explain how to use Pip command to install and manage the Python packages.

Prerequisites

  • A server running Ubuntu 20.04.
  • A root password is configured on your server.

Install Pip for Python 3 on Ubuntu

By default, Python 3 comes pre-installed in the Ubuntu 20.04. You can verify the installed version of Python3 with the following command:

python3 --version

You should see the following output:

Python 3.8.2

Next, install the Pip for Python 3 with the following command:

apt-get update -y
apt-get install python3-pip -y

Once the installation is completed, verify the installed version of Pip with the following command:

pip3 --version

You should see the Pip version in the following output:

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

To list all options available with pip command, run the following command:

pip3 --help

You should see all options in the following output:

Usage:   
  pip3  [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

Install Pip for Python 2 on Ubuntu

By default, Python 2 is included in the Ubuntu 20.04 Linux standard repository. You can install it with the following command:

apt-get install python2 -y

Once the Python 2 is installed, you will need to download the get-pip.py script to install the Pip for Python 2.

You can download the get-pip.py script using the following command:

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

Once downloaded, run the script to install pip for Python 2:

python2 get-pip.py

Once the installation has been finished, verify the installed version of Pip with the following command:

pip2 --version

You should get the Pip version in the following output:

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

Working with Pip

In this section, we will explain some basic pip command that will help you when you are working on the Python development project.

Upgrade Pip to the Latest Version

It is always a good idea to update Pip to the latest version. You can upgrade it with the following command:

pip3 install --upgrade pip

Install Packages with Pip

You can install any package for your Python project using the pip command easily. The basic syntax to install any package with pip as shown below:

pip3 install package-name

For example, you can install the TensorFlow using the pip command as shown below:

pip3 install tensorflow

If you want to install multiple packages then you can place all packages inside requirements.txt file and install all of them with the following command:

pip3 install -r requirements.txt

If you want to upgrade any installed pip package to the latest version, run the following command:

pip3 install --upgrade package-name

List Installed Packages with Pip

You can list all installed pip packages using the following command:

pip3 list

Uninstall or Remove Pip Packages

You can uninstall any pip package easily using the following command:

pip3 uninstall package-name

Conclusion

In the above post, you learned how to install Pip for Python 3 and Python 2. You also learned how to use the pip command to install and manage Python packages.

About Hitesh Jethva

I am Hitesh Jethva Founder and Author at LinuxBuz.com. I felt in love with Linux when i was started to learn Linux. I am a fan of open source technology and have more than 15+ years of experience in Linux and Open Source technologies.

View all posts by Hitesh Jethva