It is not false to say that Installing Pip on Ubuntu is really necessary for people with any level of involvement with virtual machines. Pip lets you install packages of software written in the Python programming language. In this tutorial, you will learn How to Install Pip on Ubuntu. In the end, you are an expert in installing Pip on Ubuntu using Python 2 & Python 3. Also, this guide would explain the way you can install a pip package and finally, using pip is what you will learn. But first, you need to get familiar with its exact definition, function, and features.
Prerequisites to Install Pip on Ubuntu
Before tracing the installation steps in this guide, make sure you are considering the below ones to get ready to Install Pip on Ubuntu.
- log in as root or a user with
sudoprivileges and a basic firewall.
- A system running Ubuntu.
While using Pip is recommended within a virtual environment, an Ubuntu server is required. To buy a VPS with Ubuntu, check some cheap but reliable plans to purchase your own VPS and continue learning with this article.
What is Pip? How Does it work?
Pip is an installing Python packages tool. To search, download, and install packages from Python Package Index and other package indexes, you need to install Pip. In 2008, ”Ian Bicking” introduces a tool as Pip. What does Pip do? As a package manager for Python, you can use it to install and manage libraries and dependencies that aren’t distributed as part of the standard library. A package contains all the files you need for a module. Modules are Python code libraries you can include in your project.
The package manager will resolve all dependencies and determine whether the selected software packages have already been installed when a user installs Python packages using pip. Pip will put the programs on the computer if it discovers that they aren’t already there.
Tutorial Install Python Pip on Ubuntu 18.04 & 20.04
As a VPS administrator, software developer, or user, you will find Pip useful on your Ubuntu system. It is a package management system and this guide will teach you the way you can install Pip for Python 2 and Python 3 on Ubuntu 18.04 and Ubuntu 20.04 quickly and easily.
If you are running Ubuntu 20.04, Python 3 is included in its base system installation. Python 2 is available for installation from the Universe repository. As it is expected, Python 3 packages are prefixed with python3, and Python 2 packages are prefixed with python2.
Since a Python module is tested to work properly on the Ubuntu system, you are recommended to install the module’s deb package with the
apttool. But if there is no deb package for that module, you can use pip to install a module globally.
Pip enables you to install and manage Python packages. A Python package includes Python modules that contain definitions and statements of Python and runnable code. Since Pip connects to the Python Package Index (PyPI), it makes the installation process, Python modules, and package managing easy.
How to Install Pip for Python 2 on Ubuntu
Once you purchased your Ubuntu Operating System, you are ready to install Pip on Ubuntu. Depending on which Ubuntu version you are running, in this section, the required commands are provided step by step to help you install Pip for Python on Ubuntu 18.04 and Ubuntu 20.04.
Since Pip and Python are not installed on Ubuntu 18.04 by default, you need to install them manually by running command lines.
So, open the Terminal by pressing Ctrl+Alt+T and follow the steps below to start the install Pip on Ubuntu.
Run the following command to check if your Ubuntu 18.04 system is running Python 2 or not.
To update the repository package list, type:
sudo apt update
Now, you can use the command below to install Python 2 and Pip. Running this command will install all the dependencies required for building Python modules will be installed too.
sudo apt install python-/pip
If you are prompted, press Y or Enter to complete the installation. Then, you can put the command below to check whether Pip is installed correctly or not.
So, if your Pip version is displayed in the output, the installation has been successful. But keep in mind that you may find out that the installed version is different from the version of Pip you have installed on your Ubuntu system.
Using Pip, you can install a file – requirements.txt – which contains a list of all the packages. To install the requirements, run the command below:
sudo pip install -r requirements.txt
At the time this article is being written, the latest version of Pip that supports Python 2 is the 20.3.4 version. To make sure you have the latest version, you can upgrade Pip to the latest version. So, run:
sudo pip install --upgrade pip
That’s all you need to do to Install Pip for Python on your Ubuntu 18.04 system.
Since Pip Python 2 is not included with Ubuntu 20.04, you need to use the get-pip script to install Pip for Python on Ubuntu 20.04. So, open the terminal window by pressing Ctrl+Alt+T and follow the steps below to install Pip on Ubuntu.
Run the following command to update the repository package list.
sudo apt update
If you have not installed Python 2, use the command below to install it first.
sudo apt install python2
Now, you can download the get-pip.py script by running the curl command.
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
Once the script is downloaded, as a Python 2 sudo user, run the command below to install Pip at your system level. But if you prefer to only install Pip on your account, you must run the script without sudo.
sudo python2 get-pip.py
Then, try to check if Pip has been installed successfully by running the command below and viewing the current version:
You may view something like the following output due to the installed version of Pip on your Ubuntu system.
pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
that’s it. Installing Pip for Python on your Ubuntu 20.04 system requires all the above 5 steps.
How to Install Pip for Python 3 on Ubuntu
In the previous section, you learned how to install Pip for Python 2 on two different most used versions of Ubuntu. In this part, you will also learn to install Pip for Python 3 on the same versions of Ubuntu. Let’s get started.
Ubuntu 18.04 has Python 3 installed by default. But it is possible to install Pip3 (Pip for Python 3) manually. So, to start the installation, open the terminal and follow the following steps.
As a routine in this guide, run the command below command to update the repository package list.
sudo apt update
Then, use the following command to install pip for Python 3 and all the dependencies.
sudo apt install python3-pip
Type Y or press Enter when you are asked to let the installation be confirmed.
To verify the installation, run the following command and check your Pip version number. Obviously, you will see the output related to the installed Pip version.
Now, you can upgrade Pip to the latest version by running the command below.
sudo pip3 install --upgrade pip
The recent above 4 steps will install Pip for Python 3 on Ubuntu 18.04 if you follow them successfully.
As a root or sudo user, open your terminal and run the commands below to install Pip for Python 3 on Ubuntu 20.04. then, follow the required steps.
To update your running system and install all the dependencies required for building Python modules, type the following command.
sudo apt update sudo apt install python3-pip
Once the installation is complete, run the command below to verify the installation by checking the pip version.
Your current version might be different from what you see in below, but it will be like this generally.
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
How to Install Packages with Pip
Till now, Pip must have been installed on your Ubuntu system. So, you are ready to use the following commands to install Python packages found in the Python Package Index with Pip and manage them.
The commands which are used in this part, are applicable to Python 3. So, it is clear that the commands you need to use depend on the version of Python installed. However, if you use Python 2, keep in mind to replace ”pip3” with ”pip” in all commands.
First, use the following command to install a package.
pip3 install <package name>
To install a package for example called ‘’Scrapy’’, which is used for scraping and extracting data from websites, type:
pip3 install scrapy
When you need to install a specific version of a package with pip, specify the version number in the command. The below command shows how you can install Scrapy 1.5
pip3 install scrapy==1.5
Use the following command to update an installed package to the newest version that’s available on the Python Package Index.
pip3 install <package_name> --upgrade
Anytime you want to update Scrapy on a machine that is running Python 3, you should put:
pip3 install scrapy --upgrade
How to Uninstall Pip packages
If you prefer to remove installed pip packages on Python 3, type:
pip3 uninstall <package_name>
How to Use Pip on Ubuntu
What can you do with Pip? Installing packages from PyPI, version control, local projects, and distribution files. Let’s see some useful basic Pip commands.
Anytime you need to view the list of all pip commands and options, run the command below to do this.
Also, using the
pip <command> --help command lets you get more information about a specific command. For example, using the following command helps you to get more information about the install command.
pip3 install --help
To find more useful information and the way you can use Pip, refer to the User Guide page of Pip.
Since Python Virtual Environments allows you to install Python modules in an isolated location for a specific project (rather than being installed globally) you do not have to worry about affecting other Python projects.
in this article, you learned How to Install Pip on Ubuntu. After reviewing the ways you can install pip on Ubuntu machines running both Python 2 and Python 3, you learned how you can use pip to install a Python package and upgrade it to the latest version. Install Pip on Ubuntu helps you to start managing Python packages. As a helpful command line package manager and installer for Ubuntu, pip enables you to manage Python software packages from the Ubuntu terminal. Share with us if you have any other experience using Pip on Ubuntu.