On this short article we will learn how to install pip (Package Installer for Python) for Python 2 and pip for Python 3 on Ubuntu 20.04 LTS operating system.
Introduction
Package Installer for Python (pip) is the de facto and recommended package-management system written in Python and is used to install and manage software packages. Most distributions of Python come with pip preinstalled. On this article, we will learn how to install pip for Python 2 and pip for Python 3.
On Ubuntu operating system version, starting from Ubuntu 20.04, Python 2 is available for installation from the Universe repository while Python 3 is included in the base system installation. For this reason, users are advised to switch to Python 3.
The article structure will be as following :
Install pip For Python 2
1. Update Repository
2. Adding Universe Repository
3. Install Python 2
4. Download get-pip.py Script And Install pip
5. Verify pip Installation
Install pip For Python 3
1. Update and Install Python3 pip
2. Verify pip Version for Python 3
Install pip For Python 2
As mentioned above, if pip for Python 2 is not included in the Ubuntu 20.04 repositories but available on Universe repository. For install pip for Python 2 we have to user get-pip.py
command. For installing pip for Python 2 will be performed as following task.
1. Update Repository
By updating repository, we will refresh our system to the latest package version, this task is performed by submitting command line :
$ sudo apt update
2. Adding Universe Repository
We will add universe repository to our Ubuntu system, by submitting command line :
$ sudo add-apt-repository universe
3. Install Python 2
To take effect of adding new repository, we will update system again by submitting command line :
$ sudo apt update $ sudo apt install python2
Output :
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 Get:1 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 libpython2.7-minimal amd64 2.7.18-1~20.04.1 [335 kB] Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 python2.7-minimal amd64 2.7.18-1~20.04.1 [1,285 kB] . . . Setting up libpython2.7-stdlib:amd64 (2.7.18-1~20.04.1) ... Setting up python2.7 (2.7.18-1~20.04.1) ... Setting up libpython2-stdlib:amd64 (2.7.17-2ubuntu4) ... Setting up python2 (2.7.17-2ubuntu4) ... Processing triggers for mime-support (3.64ubuntu1) ... Processing triggers for gnome-menus (3.36.0-1ubuntu1) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for desktop-file-utils (0.24-1ubuntu2) ...
4. Download get-pip.py Script And Install pip
By using curl command line, we will download get-pip.py script. We will subnit command line :
$ curl https://bootstrap.pypa.io/pip/2.7/get-pip.py –output get-pip.py
Output :
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
Then run the script with sudo user with python2 to install pip for Python 2, as shown below:
$ sudo python2 get-pip.py
Output :
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
5. Verify pip Installation
We will verify the pip for Python2 installation by querying its version.
$ pip2 --version
Output :
mpik@otodiginet:~$ pip2 --version pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
Install pip 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.
1. Update and Install Python3 pip
$ sudo apt-update $ sudo apt install python3-pip
Output :
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 libc6-dbg libc6-dev libcrypt-dev libctf-nobfd0 libctf0 libexpat1-dev libfakeroot libgcc-9-dev libitm1 liblsan0 libpython3-dev libpython3.8-dev libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev python-pip-whl python3-dev python3-distutils python3-setuptools python3-wheel python3.8-dev zlib1g zlib1g-dev Suggested packages: binutils-doc debian-keyring g++-multilib g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison gcc-doc gcc-9-multilib gcc-9-locales glibc-doc libstdc++-9-doc make-doc python-setuptools-doc The following NEW 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-dev libcrypt-dev libctf-nobfd0 libctf0 libexpat1-dev libfakeroot libgcc-9-dev libitm1 liblsan0 libpython3-dev libpython3.8-dev libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev python-pip-whl python3-dev python3-distutils python3-pip python3-setuptools python3-wheel python3.8-dev zlib1g-dev The following packages will be upgraded: libc6 libc6-dbg zlib1g 3 upgraded, 43 newly installed, 0 to remove and 386 not upgraded. Need to get 41.7 MB/54.9 MB of archives. After this operation, 216 MB of additional disk space will be used. Do you want to continue? [Y/n] Y ... etting up g++ (4:9.3.0-1ubuntu2) ... update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode Setting up build-essential (12.8ubuntu1.1) ... Setting up python3-dev (3.8.2-0ubuntu2) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9) ...
Verify pip Version for Python 3
We will verify the pip for Python2 installation by querying its version.
$ pip3 --version
Output :
mpik@otodiginet:~$ pip3 --version pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
Conclusion
On this tutorial, we have learnt how to install pip for Python 2 and Python 3 succesfully.