How to Install Python Pip on Ubuntu Linux

|

|

The article provides a comprehensive tutorial on how to install and use Python Pip on Ubuntu Linux. Pip, a Python package manager, is essential for installing, maintaining, and upgrading Python packages. The article provides detailed instructions on installing Pip for Python 3 and Python 2, using it to install Python packages, and creating a virtual…

This article describes installing and using Python pip on Ubuntu Linux.

Pip is a Python package manager for installing, maintaining, and upgrading Python packages.

Installing Python Pip on Ubuntu Linux is essential for managing Python packages. Pip is a package manager that allows users to install, maintain, and upgrade Python packages.

It searches, downloads, and installs packages from the Python package index and other indexes. Without Pip, it becomes difficult to manage Python packages.

Users can easily install Python packages and their dependencies by installing Pip on Ubuntu Linux. Pip is also used within Python virtual environments, allowing users to isolate dependencies for specific projects.

How to install Python Pip on Ubuntu Linux

As described above, Pip is a Python package manager for installing, maintaining, and upgrading Python packages. It searches, downloads, and installs packages from the Python package index and other indexes.

Below is how to install it on Ubuntu Linux.

Install Pip for Python 3

If you’re running the latest Python version and wish to use Pip to manage packages, 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 required for PiP to function will be installed alongside PiP.

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

pip3 --version

You should see a similar line below:

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

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

Install Pip for Python 2

If you want Python 2 for legacy systems, then use the steps below to install it and Pip for Python 2.

Again, PiP isn’t installed with Ubuntu, so you must run the commands below to install it.

sudo add-apt-repository universe
sudo apt update
sudo apt install python-pip

Now that Python 2 is installed, you can install Pip using a get-pip.py script. After enabling and installing the repository above, simply download and run the script to install Python globally.

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

The script will also install Pip, setup tools, and a wheel.

Installing Packages with PiP

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

If you don’t know 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

Creating a virtual environment is always a good idea when working with Python projects. Generally, the PiP package installer is used within Python virtual environments where each environment is isolated for specific projects.

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

You want to create a PiP virtual environment within your home folder or directory for this post.

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

First, install the 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 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-OpenStack client 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 finish the Python project, simply run the deactivate command to return to your standard shell.

deactivate

That’s it!

Conclusion:

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


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



One response to “How to Install Python Pip on Ubuntu Linux”

  1. Bishwas Avatar
    Bishwas

    Try using sudo apt-get update && upgrade before installation. If you’re still having issue, check this forum post to install pip in wsl: https://webmatrices.com/d/135-wsl-install-pip/2

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading