How to Install Python PIP on Ubuntu 18.04

Filed Under: Ubuntu

Pip (Pip Install Packages) is a command line utility tool used to install and manage software packages written in Python. Like apt and yum, it is a package management system and mainly used to download and install packages from the Python Package Index (PyPI). Pip does not get installed by default in Ubuntu 18.04. However, the installation of Python Pip using the apt package manager is very simple.

This tutorial will show you how to install python Pip in your Ubuntu 18.04 system using apt. Thereafter, we will also check a few essential usages of Python Pip.

Prerequisite

  • You can open a SSH session in your Ubuntu 18.04 system using root or a sudo enabled user.

Pip for Python 3

Ubuntu 18.04 ships with Python 3 and therefore you need to install pip3 specifically for python 3. To start with, update the package list in your system:


# apt update

Next, execute the following command to install Pip for python 3 and all the dependencies needed for designing Python modules.


# apt install python3-pip

Finally, find the version of Pip to verify the installation:


# pip3 --version
PIP install Ubuntu 18.04

PIP3 Version

Pip for Python 2

Although Python 3 is installed by default in Ubuntu 18.04, it is very much possible to have both Python 2 and Python 3 installed in your system. So if you want to manage packages for Python 2, you need to install pip for Python 2.

Start by updating the package list in your system.


# apt update

Now install pip for Python 2 along with all other dependencies for building Python modules using following apt command:


# apt install python-pip

Remember, the above command will install Python 2 as well if you have not installed it previously.

Finally, find the version of Pip to verify the installation:


# pip --version
Python 2 PIP install Ubuntu 18.04

PIP Version

Essential Pip Commands

At this point, Pip should be installed in your system. Let us walk through a few useful pip commands to get you started with it.

Pip should be used within Python virtual environments which allows you to install and manage packages in a secure way for each Python projects separately. This ensures installing or deleting packages from one Python project does not affect another.

Although this tutorial will not cover about Python virtual environment or how to create it, you can use the following Pip commands either inside Python virtual environment or outside it.

1. List installed packages

To find all the installed Pip packages run the following command from the terminal:


# pip3 list

2. Search package

To search packages from the Python Package Index, execute the following pip command from the terminal:


# pip3 search keyword

3. Install packages

To install the latest version of Python package using Pip, use the following command from the terminal.


# pip3 install package_name

It is also possible to install a specific version of Python package by specifying the version number with Pip command.


# pip3 install package_name==2.1

4. Install packages using requirements.txt

Sometimes you want to install multiple packages with the specific version number for your Python project. You can list the name of all the packages that need to be installed along with their version number in the requirements.txt file.

To use requirement file for installing packages, create and edit a file by the name requirements.txt and specify a list of packages along with their version number in it.


# vi requirements.txt
certifi==2018.11.29
chardet==3.0.4
idna==2.8

Now to install packages, run the pip3 install command by specifying requirements file using the -r switch:


# pip3 install -r requirements.txt

5. Upgrade package

To upgrade an installed package, use the --upgrade switch along with package name like the following command.


# pip3 install --upgrade package_name

6. Delete package

To remove an installed package, specify the package name to be deleted with the pip command:


# pip3 uninstall package_name
If you are using Python 2 then replace pip3 with pip in the above pip commands.

Summary

In this tutorial, we have covered how to install Pip for Python 2 and Python 3 in an Ubuntu 18.04 system. Further, we have also covered a few basic usages of Pip to get you started with it. You can always invoke pip manual pages by using pip3 --help from terminal to find more options and usages of python Pip.

Leave a Reply

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

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages