Install Python Pip on Ubuntu 18.04

Installing Python Pip on Ubuntu 18.04

Overview

In this tutorial, you will learn how to install Python Pip onto Ubuntu 18.04. Pip is a package management system for Python that allows you to install and manage software packages written in Python.

Installing Pip

Python Pip is available from the the Ubuntu 18.04 source repositories, and it can easily be installed without additional work. The version available for Ubuntu 18.04 is 9.0.1.

There are two versions of Pip that can be installed, one for Python 2.7 and the other for Python 3. The latter is the recommended version, as the former will be deprecated in the near future.

Install Python Pip for Python 3

sudo apt install python3-pip

To install Python Pip for Python 2.7, use the following command instead.

sudo apt install python-pip

Pip Installation Script

An alternative to installing Pip from the Ubuntu Apt repository is to run an installation script provided by pypa.com. This is useful for distribution that do not have Pip available in their package manager, or when you want more installation options.

Apt will not be aware of Pip when installed using this script. If Pip is already installed via Ubuntu’s package manager, installing it again using the installation script could put your server into an inconsistent state.

Download the installation script for Pip from pypa.com

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

Execute the script using Python

python get-pip.py

Updating Python Pip

Pip is capable of updating itself using the pip install command. When executed, Pip will look for an updated version of itself and then install it.

To update Pip, run the following command

pip install -U pip

Intalling Packages

To install a new package using Python Pip, the pip install command is used with the name of the package to be installed.

pip install PACKAGE_NAME

For example, to install Ansible through Pip you would run the following command.

pip install ansible

Update Installed Packages

Packages are frequently updated, and to ensure you are running the latest version that fix bugs, security vulnerabilities, or add new features, you use the pip install command with the -U flag.

pip install -U PACKAGE_NAME

For example, to update the Ansible package you would run the following command.

pip install -U ansible

Remove Installed Packages

To uninstall and remove packages from Ubuntu 18.04, the pip uninstall command is used.

pip uninstall PACKAGE_NAME

For example, to uninstall the Ansible package from Ubuntu 18.04 you would run the following command.

pip uninstall ansible

Listing All Installed Packages

To list packages installed using Pip, you can use the list command. The pip list command will output each install package with its version.

pip list

Listing All Outdated Packages

Keeping an eye on outdated packages is simply using the outdated list option. A nicely formatted list of outdated packages that are installed on the system by pip will be outputted.

pip list --outdated

Show Information about Install Package

To show detailed information about a package that is installed on the server, the pip show command can be used. Included in the output of this command is the package name, version, a short summary, and a dependency tree.

pip show <package name>