How to install Pip on Ubuntu 18.04

s2 0

Pip is a package management system that simplifies the installation and management of software packages written in Python, such as those found in the Python Package Index (PyPI). Pip isn’t installed by default on Ubuntu 18.04, but installing it is pretty straightforward.

In this tutorial, we are going to show you how to use Python Pip on Ubuntu 18.04 with the apt
Package manager. We’ll also walk you through the basics of installing and managing Python packages with pip.

requirements

Before proceeding with this tutorial, make sure that you are logged in as a user with sudo permissions.

Install Pip for Python 3

Ubuntu 18.04 comes with Python 3 as the standard Python installation. Follow the steps below to install pip (pip3) for Python 3:

  1. Start updating the package list with the following command:

    sudo apt update
  2. Use the following command to install pip for Python 3:

    sudo apt install python3-pip

    The above command also installs all of the dependencies needed to build Python modules.

  3. Once the installation is complete, verify the installation by checking the Pip version:

    pip3 --version

    The version number can vary, but looks something like this:

    pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

Install Pip for Python 2

Python 2 is not installed by default in Ubuntu 18.04. To install Python 2 and pip for Python 2, do the following:

  1. Update the package index by running the following command:

    sudo apt update
  2. Install pip for Python 2 with:

    sudo apt install python-pip

    The above command installs Python2, Pip, and any dependencies needed to build Python modules.

  3. Verify the installation by printing out the Pip version number:

    pip --version

    The version number can vary, but looks something like this:

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

How to use Pip

When installing Python modules globally, it is strongly recommended to use the Python modules provided by the distribution with the apt
Package managers because they have been tested on Ubuntu systems.

You should only install Python modules globally with pip if no package is available through the package manager.

In most cases, you should only use pip in a virtual environment. python Virtual Environments allows you to install Python modules in an isolated location for a specific project instead of being installed globally. That way, you don’t have to worry about affecting other Python projects.

In this section, we will show you some useful basic Pip commands. With pip we can install packages from PyPI, version control, local projects and from distribution files, but in most cases you will be installing packages from PyPI.

To see the list of all Pip commands and options, type:

pip3 --help

For more information on a specific command, contact pip <command> --help . For example, for more information about the installation command, type:

pip3 install --help

Packages with pip. to install

For example, suppose you want a package called. to install scrapy which is used for scraping and extracting data from websites.

To install the latest version of the package, you need to run the following command:

pip3 install scrapy

To install a specific version of the package, enter the following command:

pip3 install scrapy==1.5
Substitute pip3 With pip if you are using Python 2.

Install packages with Pip using the requirements files

requirement.txt is a text file that contains a list of Pip packages with their versions that are required to run a particular Python project.

Use the following command to install a list of requirements specified in a file:

pip3 install -r requirements.txt

List installed packages

To list all installed pip packages use the following command:

pip3 list

Upgrade a package with Pip

To update an installed package to the latest version, do the following:

pip3 install --upgrade package_name

Packages with pip. uninstall

To uninstall a package, do the following:

pip3 uninstall package_name

Conclusion

In this tutorial you learned how to install pip on your Ubuntu machine and how to manage Python packages with pip. For more information on pip, see the pip user manual
Page.

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