How to Install PiP on Ubuntu 18.04 | 16.04

This brief tutorial shows students and new users how to install and use PiP on Ubuntu 18.04 | 16.04.

For those who don’t know, PiP is a package installer used to install and manage software packages written in Python. Users can use PiP to install packages from the Python Package Index and other indexes.

PiP isn’t installed by default on Ubuntu. But installing it is pretty easy and straightforward. The steps below will guide you through the installation and management of Python packages via PiP.

For student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices…

When using Ubuntu, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using the system to get work done.…

Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses.

Step 1: Install PiP For Use with Python 3

If you’re running the latest Python version and you wish to use PiP to manage packages, then use the steps below.

The commands below install PiP to be used with Python version 3.

sudo apt update
sudo apt install python3-pip

When you run the commands above, all dependencies that are required to for PiP to function will be installed along side PiP.

To validate whether PiP is installed, simply run the commands below:

pip3 --version

You should see similar line as below:

Output:
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

That’s how to get PiP installed for use with Python 3.

Step 2: Install PiP for Use with Python 2

If you’re currently using Python 2 and previous, then the steps to get PiP installed and use is using the commands below.

Again, PiP doesn’t come installed with Ubuntu, so you will have to run the commands below to install it.

sudo apt update
sudo apt install python-pip

After installing, simply run the commands below to validate wither PiP is installed and ready to use.

pip --version

You should see similar output as below:

Output:
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

With these commands, you have installed PiP for Python versions 2 and 3.

Step 3: Installing Packages with PiP

Now that PiP is installed, you can begin installing Python packages using it.

If you don’t already how to use PiP, simply run its help command to display helpful command options and how to use them..

pip3 --help
pip install --help

You should see helpful commands and how to use them as shown below

Usage:   
  pip  [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.
  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.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding
                              to WARNING, ERROR, and CRITICAL logging levels).
  --log                 Path to a verbose appending log.

When working with Python projects, it’s always a good idea to create a virtual environment. Generally PiP package installer is used within Python virtual environments where each environment are isolated for specific projects.

After each project is done, it can be discarded easily.

For this post, you want to create a PiP virtual environment within your home folder or directory.

Simply run the command below to create a Python 3 virtual environment called confidential.

First install Python virtual environment module by running the commands below:

sudo apt install python3-venv

Then create a new environment called confidential

python3 -m venv ~/confidential

Simply activate the environment by running the commands below:

source ~/confidential/bin/activate

Within this specific environment, you can begin installing packages via PiP to use with Python 3.

For example, to install a Python package called python-openstackclient, simply run the commands below:

Example:

pip3 install python-openstackclient

That should install the python-openstackclient package to use with Python 3.

To upgrade packages via PiP, simply run the commands below:

pip3 install --upgrade python-openstackclient

To uninstall packages via PiP, simply run the commands below:

pip3 uninstall python-openstackclient

When you’re done with the Python project, simply run the deactivate command to return to your normal shell.

deactivate

That’s it!

Conclusion:

This post shows you how to install PiP on Ubuntu 18.04 | 16.04 to to install and manage Python packages or modules. If you find any error above, please use the comment form below to report it.

You may also like the post below:

Setup Perch CMS on Ubuntu 18.04 | 16.04 with Nginx

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.