How to Install Python pip on Ubuntu 22.04

If you are a python programmer or learning python for the first time often you required to install additional packages that are not available in the default python library here PIP comes in to save you time. Pip is a package manager for Python similar to apt in ubuntu. With the help of pip, you can install and upgrade the latest packages configure, and manage project dependencies.

In this article, I have created a step-by-step guide to installing Python pip on Ubuntu 22.04 for Python 3 and Python 2.

How to install pip python?

Python 3 is the latest and greatest version but there are some projects when you need to use Python 2. The latest Ubuntu 22.04 comes pre-installed with Python 3 and it is recommended to use. Python 2 can be installed on the system by using apt. Always use pip to install a module globally only if there is no deb package for that module.

it is recommended to use pip within a virtual environment only. In a nutshell, Python virtual environments help decouple and isolate Python installs and associated pip packages. This allows end-users to install and manage their own set of packages that are independent of those provided by the system or used by other projects.

Installing pip for Python 3

Ubuntu 22.04 makes Installing pip for Python 3 a lot easier run the following commands as sudo user in the Ubuntu terminal:

sudo apt update
sudo apt install python3-pip
Installing pip for Python 3
Installing pip for Python 3

sudo apt install python3-pip commands will install pip along with all the required dependencies for building Python modules.

Once pip is installed you can verify the installation by running checking the pip version:

pip3 --version

Output:

pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)

Installing pip for Python 2

Python 2 pip is no longer available in Ubuntu 22.04 repositories. To install pip for Python 2 we will be using get-pip.py script.

Install python 2 in Ubuntu 22.04.

sudo apt update 
sudo apt install python2

Now we will use curl to download the get-pip.py script on our pc:

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

So, it’s time to run the script as a super user (sudo) user using the python2 binary to install pip for Python 2:

sudo python2 get-pip.py

This script will install pip for Python 2 globally along with the setuptools and wheel packages that allow you to install source distributions.

Verify the installation by printing the pip version number:

pip2 --version

Output:

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

Installing Packages with Pip

python -m pip install [options] <requirement specifier> [package-index-options] ...
python -m pip install [options] -r <requirements file> [package-index-options] ...
python -m pip install [options] [-e] <vcs project url> ...
python -m pip install [options] [-e] <local project path> ...
python -m pip install [options] <archive url/path> ...

1. Install SomePackage and its dependencies from PyPI using Requirement Specifiers.

python -m pip install SomePackage            # latest version
python -m pip install SomePackage==1.0.4     # specific version
python -m pip install 'SomePackage>=1.0.4'   # minimum version

2. Install a list of requirements specified in a file. See the Requirements files.

python -m pip install -r requirements.txt

3. Upgrade an already installed SomePackage to the latest from PyPI.

python -m pip install --upgrade SomePackage

More from this stream

Recomended