October 21, 2021
How to install python pip2 and python pip3

How To Install pip On Ubuntu 20.04 LTS

On this article we will learn how to install pip for Python 2 and pip for Python 3 on Ubuntu 20.04 LTS operating system.

Introduction

if we are going to develop a python based application, we will face with the difficulty of finding and managing what packages we will use. For this need, a PIP was made. PIP is a package contains all the files we need for a module. Modules are Python code libraries we can include in our project. On this article, we will learn how to install pip for Python 2 and Python3 on Ubuntu 20.04 LTS operating system.

pip Installation On Ubuntu 20.04 LTS

Before starting installation, we are advised to update our system first. By updating our system, it will refresh the local list of available software packages. To update system repositories, we will use the command line : sudo apt update.

mpik@otodiginet:~$ sudo apt update
[sudo] password for mpik: 
Hit:1 http://ppa.launchpad.net/ondrej/php/ubuntu focal InRelease                                                   
Hit:2 http://us.archive.ubuntu.com/ubuntu focal InRelease                                                          
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]                 
Get:5 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]                                         
Get:6 https://dlm.mariadb.com/repo/mariadb-server/10.6/repo/ubuntu focal InRelease [6,264 B]                       
Hit:3 https://downloads.mariadb.com/Tools/ubuntu focal InRelease                                                   
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [793 kB]                     
Get:9 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]                                       
Hit:7 https://downloads.mariadb.com/MaxScale/2.5.14/apt focal InRelease                                            
Get:10 http://us.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [518 kB]
Get:11 https://dlm.mariadb.com/repo/mariadb-server/10.6/repo/ubuntu focal/main amd64 Packages [17.3 kB]
Get:12 https://dlm.mariadb.com/repo/mariadb-server/10.6/repo/ubuntu focal/main arm64 Packages [16.6 kB]  
Ubuntu 20.04 LTS update Repositories
Ubuntu 20.04 LTS update Repositories

1. pip installation for Python 2

The pip for Python 2 is not included in Ubuntu 20.04 repositories, so we will be using get-pip.py script for installing pip for Python 2. The installation process is starting by adding universe repository to our Ubuntu 20.04 LTS system. The command line is : sudo add-apt-repository universe.

mpik@otodiginet:~$ sudo add-apt-repository universe
'universe' distribution component is already enabled for all sources.

Then we will install Python 2 on the system, by submitting command line : sudo apt install python2.

mpik@otodiginet:~$ sudo apt install python2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libevent-core-2.1-7 libevent-pthreads-2.1-7 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python2-minimal python2.7 python2.7-minimal
Suggested packages:
  python2-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
  libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python2 python2-minimal python2.7 python2.7-minimal
0 upgraded, 7 newly installed, 0 to remove and 389 not upgraded.
Need to get 3,816 kB of archives.
After this operation, 16.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Install Python 2
Install Python 2

Then we will download pip for Python 2 package by using command line : curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py.

mpik@otodiginet:~$ curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1863k  100 1863k    0     0  1680k      0  0:00:01  0:00:01 --:--:-- 1680k

After the package was downloaded, then we will install it by using command line : sudo python2 get-pip.py.

mpik@otodiginet:~$ sudo python2 get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting pip<21.0
  Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 1.6 MB/s 
Collecting setuptools<45
  Downloading setuptools-44.1.1-py2.py3-none-any.whl (583 kB)
     |████████████████████████████████| 583 kB 2.4 MB/s 
Collecting wheel
  Downloading wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-20.3.4 setuptools-44.1.1 wheel-0.37.0
Install pip2 on Ubuntu 20.04 LTS
Install pip2

pip for Python 2 has been installed successfully. We will verify the installation by submitting command line : pip2 --version.

mpik@otodiginet:~$ pip2 --version
pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
pip3 --version : query pip2 version on Ubuntu 20.04
pip2 –version

2. pip installation for Python 3

On this stage, we will install pip for Python 3 on Ubuntu 20.04 by submitting commands as root or sudo user: sudo apt install python3-pip.

mpik@otodiginet:~$ sudo apt install python3-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libevent-core-2.1-7 libevent-pthreads-2.1-7 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential dpkg-dev fakeroot g++ g++-9 gcc gcc-9
  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6
Install pip3 for Python 3
Install pip3 for Python 3

Once the installation is complete, then we verify the installation by checking the pip version, by submitting command line : pip3 –version.

mpik@otodiginet:~$ pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
pip3 --version : query pip3 version on Ubuntu 20.04
pip3 –version

How to Use pip

By using pip, we can install any packages from PyPI, version control, local projects, etc. At the end, as a summarize of pip usage, we can see at the command line of pip --help.

mpik@otodiginet:~$ pip3 --help

Usage:   
  pip3 <command> [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.
  config                      Manage local and global configuration.
  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.
  debug                       Show information useful for debugging.
  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>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in
                              PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for
                              download. Implied with --no-index.

Conclusion

So far, we have shown you how to install pip on Ubuntu 20.04 LTS system. I hope this article can be useful for readers who need useful information about installation and usage of pip2 and pip3.

Share this article via :

Leave a Reply

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