Categories
Linux

How to Install and Use Pip on Ubuntu 20.04

pip is the standard package management tool for software written in Python. It installs software, and their dependencies from the standard Python repository, Python Package Index, by default.

Although the usual package manager apt can be used, it has several downsides when it comes to regularly updated versions of Python code, non availability of number of Python packages, and so on.

Installing Pip in Ubuntu

Pip is available in standard Ubuntu software repository.

For installing Pip for Python 2 packages, you can run the following :

sudo apt install python-pip

For installing pip for Python 3 packages, you can run the following :

sudo apt install python3-pip

Note: For older Ubuntu versions (version 14.04 and below), you need to use apt-get should be used instead of apt.

The Ubuntu repository is likely to not have the latest available version of pip. To upgrade pip to latest version, run the below commands:

#For Python 2 sudo pip install --upgrade pip #For Python 3 sudo pip3 install --upgrade pip

📝 Important note pip and pip3:
Command pip is used for installing Python 2 packages, while pip3 is used for installing Python 3 packages. Henceforth in the guide, examples are shown with pip3; user should use pip whenever package for Python 2 are required.


Pip List and Search commands for Python packages

To list installed python packages in system, run:

pip3 list

To show detailed information about a package, run:

pip3 show package_name

└ Replace package_name in the command above with the name of the package you want to view detailed about using pip.

To search for a package in Python Package Index using pip, run the command below:

pip3 search <keyword>

└ Replace <keyword> in the command above with your search term. The command will list all packages matching with the search keyword.

The screenshot below shows an example pip3 search for the term “blinker”.


Using pip to Install and Update packages

To install a package using pip, run:

pip3 install package_name

└ Replace package_name in the command above with the name of the package you want to install using pip.

To upgrade a package using pip, run the command below. It will recursively upgrade all dependencies of the package as well.

pip3 install --upgrade package_name

└ Replace package_name in the command above with the name of the package you want to upgrade using pip.

Uninstalling a package using Pip

Like installing and updating packages, you can also uninstall a package using pip. Run the command below to do so.

pip3 uninstall package_name

└ Replace package_name in the command above with the name of the package you want to uninstall using pip.

To uninstall a package without the program asking for a confirmation prompt, use the flag -y:

pip3 uninstall -y package_name

That’s it. We hope you find the instructions above helpful. If you have any questions, let us know in the comments section below.