PIP is a command-line package manager that helps you to install and manage software packages those written in the python programming language. Users can search for many packages and install their dependencies from the python package index. PIP package manager is not pre-installed on different Linux distributions including Ubuntu 20.04. Therefore, you need to install this utility on your system manually.
In this article, we will explain the installation procedure of PIP for both python versions Python 2 and Python 3. All steps and commands we have implemented on Ubuntu 20.04 LTS. The below-given steps are quite similar and can be implemented on older Ubuntu versions.
Pre-requirements
- You must have root or sudo privilege to run different commands.
- Ensure that python version 2 and 3 are installed on your system. Otherwise, you can install it during the PIP installation.
Installation of PIP on Ubuntu 20.04
We have executed all commands on the command line tool, therefore, we need to open the terminal application on your system. By clicking on the ‘Activities’ you will access the application launcher bar and then type ‘terminal’ in the search bar. You will see the terminal application icon in search results. Click on this icon and launch the terminal window on your system.
Update the apt packages
It is recommended that the first update and upgrade the apt packages. So, using the following command update all apt packages:
$ sudo apt update
Upgrade packages
As you can see that we need to upgrade some packages on our system. Therefore, type the following command to upgrade all apt packages:
$ sudo apt upgrade
The following output will display on the terminal:
Install PIP for Python 2
Implement the below-mentioned steps to install PIP for Python 2:
Step 1: Add repository
In Ubuntu 20.04, PIP python 2 is not included by default. Therefore, we will install PIP for python 2 using the get-pip.py script. Add and enable the universe distribution components by adding the repository. So, run the following command on the terminal to perform this action:
$ sudo add-apt-repository universe
Step 2: Install python 2
As you can see in the above screenshot, the universe distribution components are already enabled. Now, you will install python 2 on your system by executing the following command:
$ sudo apt install python2
Step 3: Download and install the required pip script
Download the required get-pip.py script by using the curl command that is not installed by default in Ubuntu 20.04. Therefore, if you have a fresh installation of Ubuntu on your system then, first you will install curl by using the following command:
$ sudo apt install curl
After that, run the following command to install get-pip.py script:
$ curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
Execute the following command to install PIP for Python 2 on Ubuntu 20.04:
$ sudo python2 get-pip.py
The following output will be retrieved on the terminal:
Step 4: Check installed version
Verify the installation of pip for python 2 by checking the pip version:
$ pip –version
You can see in the above image that the newest pip version 20.0.3 has been installed for python 2.7.
Install PIP for Python 3
Install pip3 for Python version 3. Type the following command on the terminal for this purpose:
$ sudo apt install python3-pip
Check pip installed version
Once the pip is installed for Python 3, run the following command to print the install version of pip3 on the terminal:
$ pip3 --version
How to use PIP?
In this section, we will give you some useful basic commands that will help to learn the PIP tool. You can get all commands list by using the following command:
$ pip3 --help
Search package using PIP
You can install a package using pip. But, you should be able to search the python package by using the following command:
$ pip3 search package-name
For example, we want to search the scrapy package that is used for data scraping / data extraction from different websites. So, you will run the following command to search for the scrapy package:
$ pip3 search scrapy
You will get the following output on the terminal:
Package installation using PIP
Now, you will install scrapy by executing the following command:
$ pip3 install scrapy
Uninstall a package using PIP
You may uninstall the unnecessary packages from your Ubuntu system using the python PIP tool. For example, here we want to remove the scrapy package from our system then, by using the following command we can do it:
$ pip3 uninstall scrapy
Conclusion
From the above article, now you can install Python PIP tools on Ubuntu 20.04. Moreover, we have also mentioned different commands that will help you in using the PIP tool. You can search, install and remove packages by using the pip utility.