Pip is one of the best tools to install and manage Python packages. Pip is a package management system that simplifies installation and management of software packages written in Python such as those found in the Python Package Index (PyPI)
This tutorial will show how to install Pip and show you some basic commands like installing and upgrading Python packages on Ubuntu 20.04 LTS servers.
1./ Install Pip on Ubuntu 20
01- Open a command prompt and run the below command to install Pip:
$ sudo apt install -y python3-pip
02- You can verify that Pip was installed correctly by entering the following command:
$ pip3 --version pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
03- To view the list of all Pip commands and options, type:
$ pip3 --help
2./ How To use Pip on Ubuntu
1- How To Search Packages with Pip
Once you correctly installed Pip. You can search for the packages using the search
command as below:
$ pip3 search awx awx-exporter (0.2) - cli tool to create a portable/workstation compatible version of awx/tower inventories ansible-tower-cli (3.3.9) - A CLI tool for Ansible Tower and AWX. towerlib (3.2.8) - A python library to interface with ansible tower's (awx) api. awxapis (0.6) - Helper module for utilizing Ansible Tower/AWX Apis
2- How to Find installed Pip Packages
– To get the list of the installed packages, you can run the following command:
$ pip3 list Package Version ---------------------- ------------- attrs 19.3.0 Automat 0.8.0 blinker 1.4 certifi 2019.11.28 chardet 3.0.4 Click 7.0 cloud-init 20.1 colorama 0.4.3
3- How to Install Packages with Pip
– To install the latest version of A Python package, you can use the install
command. Let’s assume that we want to install the pymetasploit3 package as below:
$ pip3 install pymetasploit3 Collecting pymetasploit3 Downloading pymetasploit3-1.0.2.tar.gz (18 kB) Collecting msgpack Downloading msgpack-1.0.0-cp38-cp38-manylinux1_x86_64.whl (303 kB) |████████████████████████████████| 303 kB 23.8 MB/s Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from pymetasploit3) (2.22.0) Building wheels for collected packages: pymetasploit3 Building wheel for pymetasploit3 (setup.py) ... done Created wheel for pymetasploit3: filename=pymetasploit3-1.0.2-py3-none-any.whl size=17048 sha256=923ae2a8be8629e20cc582f93991a84644096bb71364ae7ee1a62f9d48320eff Stored in directory: /root/.cache/pip/wheels/98/48/2d/a4166552fd5a5db76554b19e2dcd463d93283343aabac7d418 Successfully built pymetasploit3 Installing collected packages: msgpack, pymetasploit3 Successfully installed msgpack-1.0.0 pymetasploit3-1.0.2
– To install a specific version of the package you can use the following command:
$ pip3 install PACKAGE_NAME==VERSION_NUMER
– You can even install packages using a Requirements File that contains a list of pip packages with their versions that are required to run a specific Python project:
$ pip3 install -r requirements.txt
4- How to Upgrade Packages with Pip
– To upgrade a Python package you can run the following command:
$ pip3 install --upgrade PACKAGE_NAME
5- How to Remove Packages with Pip
– In order to remove any package installed with Pip, use the below command.
$ pip3 uninstall PACKAGE_NAME
Conclusion
In this tutorial, you have learned how to install Pip on your Ubuntu 20.04 LTS server and how to manage Python packages using Pip. For more information about Pip, visit the pip user guide page.