How to Install Pip on Ubuntu 16.04 Linux

The Pip is a standard package manager for Python programming language. It is use to install and manage additional packages that are not available in the Python standard library. By default, Pip is not available in Ubuntu 16.04, but we can install it using simply like any other application.

In this tutorial guide, we will show you how to install Python Pip on your Ubuntu 16.04 system using “apt” package manage (Ubuntu’s default package manager). We will also learn how to install and manage Python packages with Pip.

Prerequisites

We need a Ubuntu 16.04 system, and a user credential with sudo privileges to login into the system and run administrative command to install packages.

Install pip for Python 3

We can run Python 2 and Python 3 both in a system so in the same way we can keep pip for Python 2 and Python 3 also.

To install pip (pip3) for Python 3, follow below-given steps:

Step 01: First update the package list in Ubuntu repository using the following command:

$ sudo apt update

Step 02: Now we can install pip (pip3) and all required dependencies for Python 3 using below command:

$ sudo apt install python3-pip

Step 03: After completing the installation, verify the installation by checking the version of pip using the following command:

$ pip3 --version
Output-
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

Install pip for Python 2

If your system has Python 2 installed you can install pip for Python 2 by below steps:

Step 01: First update package list in your Ubuntu repository using the following command:

$ sudo apt update

Step 02: To install pip for python 2 use the following command:

$ sudo apt install python-pip

This command will install pip and required dependencies for building Python modules.

Step 03: After completing the installation, verify the installation by checking the version of pip using the following command:

$ pip --version
Output-
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

How to use Pip

The Pip is use to install python modules. Still, it is highly recommended to install Python modules provided by distribution using the “apt” package manager, as these are tested to work correctly on Ubuntu machine.

You should use the pip package manager to install the package globally only if the package is not provided through the default “apt” package manager.

We generally use Pip within a virtual environment. The Python “Virtual Environment” allows us to install python packages and modules in an isolated location for a single project, and it is not usable by globally. And it would be best if you are no worried about other projects as it is not affecting other projects.

In this tutorial, we will show you the use of basic pip commands. By using Pip, we can install packages from PyPI, distribution files, local projects, and from version control, but most of the cases we use it to install from PyPI.

You can check all available pip commands and options using the following command:

$ pip3 --help
how to use pip command

You can get more information about the specific pip command using “pip <commad> –help”. For example, if you want to know about “pip install” command, you can use the following command:

$ pip3 install --help

Installing Packages with Pip

In this tutorial, we will check pip installation command by installing a package called “scrapy”; it is use to scrape and extract data from websites.

To install the latest version of “scrapy” package, use the following command:

$ pip3 install scrapy

If you want to install a specific version of “scrapy” package use the command like below we use to install “scrapy” version 1.2.

$ pip3 install scrapy==1.5

Note – replate pip with pip3 if you are using Python 3.

Installing packages using the Requirements files for Pip

The “requirement.txt” file is a file containing the list of pip packages and versions, which is use to run the specific project.

To run the project without any issue, we need to install all those packages first by using the following command:

$ pip3 install -r requirements.txt

List out the installed packages

To check the all installed pip packages in the system, use the following command:

$ pip3 list

Upgrade a package using Pip

To upgrade any specific pip package to the latest version run the following command:

$ pip3 install --upgrade package_name

Uninstalling a package using Pip

To uninstall a specific pip package run the command as shown below:

$ pip3 uninstall package_name

Conclusion

Now you have learned about Python package manager called Pip. You are ready to install and configure Pip package manage in your Ubuntu 16.04 machine. You have learned how to install, upgrade, and uninstall packages using the pip package manager.

If you have any doubt, questions, or feedback, feel free to comment below.

0 Comments

Submit a Comment

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

Related Articles