Are you finding it difficult to install and use Python PIP tools on Ubuntu ?
This guide is for you.
PIP is a command-line package manager that helps you to install and manage software packages those written in the python programming language.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Linux based Configuration tasks.
In this context, we shall look into how to install and use Python PIP tools on Ubuntu 20.04 LTS.
pip is a package-management system written in Python used to install and manage software packages. It connects to an online repository of public and paid-for private packages, called the Python Package Index.
Linux 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.
To install PIP on Ubuntu, ensure that you have the following:
i. You must have root or sudo privilege to run different commands.
ii. Ensure that python version 2 and 3 are installed on your system. Otherwise, you can install it during the PIP installation.
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.
1. 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
2. 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
3. Install PIP for Python 2
Follow the steps below to install PIP for Python 2:
i. 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
ii. Install python 2
To install python 2 on your system, run the following command:
$ sudo apt install python2
iii. 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;
a. First you will install curl by using the following command:
$ sudo apt install curl
b. After that, run the following command to install get-pip.py script:
$ curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
c. Execute the following command to install PIP for Python 2 on Ubuntu 20.04:
$ sudo python2 get-pip.py
iv. Check installed version of PIP 2
Verify the installation of pip for python 2 by checking the pip version:
$ pip –version
To Install PIP3 for Python version 3, execute the command shown below:
$ sudo apt install python3-pip
Once the pip is installed for Python 3, run the following command to print the install version of pip3 on the terminal:
$ pip3 --version
Here, you will learn 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
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 Instance, If you want to search a 'location' package that is used for restaurant searching from different websites. So, you will run the following command to search for the location package:
$ pip3 search location
You can install a package (package_name) by executing the following command:
$ pip3 install package_name
To uninstall unnecessary packages from your Ubuntu system, you can use the python PIP tool. For instance, in this case we want to remove a package called "package_name" from our system then, by using the following command we can do it:
$ pip3 uninstall package_name