How to Install and Use PIP Python Package Manager on Debian 11
Pip is a widely used package manager for the Python programming language. It is being used for installing and managing additional packages that are not available in the Python standard library. It allows users to search a package from the python packages index as well as install its dependencies. Pip is also known as a "Preferred Installer Program" that can create a completely isolated environment for the Python application.
In this article, I will show you how to install and use Pip on Debian 11.
Prerequisites
- A server running Debian 11.
- A root password is configured on the server.
Install Pip for Python3
By default, Pip is not installed in the Debian 11 operating system. You will need to install separate Pip versions for Python3 and Python2.
First, install the Python3 with the following command:
apt-get install python3 -y
Once the Python3 package is installed, install the Pip for Python3 using the following command:
apt-get install python3-pip -y
Next, verify the Pip version using the following command:
pip3 --version
You will get the following output:
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)
Install Pip for Python2
First, you will need to install Python2 to your system. You can install it using the following command:
apt-get install python2 curl -y
Next, download the Pip2 installation script using the following command:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
Next, run the downloaded script to install Pip2 to your system.
python2 get-pip.py
Once installed, you can verify the Pip2 version using the following command:
pip2 --version
You will get the following output:
pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
How to Use Pip Command Line
To list all options available with Pip, run the following command:
pip3 --help
You will get the following list:
Usage: pip3[options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. config Manage local and global configuration. search Search PyPI for packages. cache Inspect and manage pip's wheel cache. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. debug Show information useful for debugging. help Show help for commands.
To install any package for Python3 like TextStatistic, run the following command:
pip3 install "TextStatistic"
Sample output:
Collecting TextStatistic Downloading TextStatistic-1.0.6-py3-none-any.whl (5.6 kB) Installing collected packages: TextStatistic Successfully installed TextStatistic-1.0.6
To install any package for Python2 like scrapy, run the following command:
pip install "scrapy"
To list all available packages, run the following command:
pip3 list
You should see the following output:
Package Version ---------------- --------- certifi 2020.6.20 chardet 4.0.0 httplib2 0.18.1 idna 2.10 pip 20.3.4 pycurl 7.43.0.6 PySimpleSOAP 1.16.2 python-apt 2.2.1 python-debian 0.1.39 python-debianbts 3.1.0 reportbug 7.10.3 requests 2.25.1 setuptools 52.0.0 six 1.16.0 TextStatistic 1.0.6 urllib3 1.26.5 wheel 0.34.2
To search for any package, run the following command:
pip3 search urllib3
To list the outdated packages, run the following command:
pip3 list --outdated
You will get the following output:
Package Version Latest Type ---------------- --------- --------- ----- certifi 2020.6.20 2021.10.8 wheel httplib2 0.18.1 0.20.1 wheel idna 2.10 3.3 wheel pip 20.3.4 21.3 wheel pycurl 7.43.0.6 7.44.1 sdist python-debian 0.1.39 0.1.40 wheel python-debianbts 3.1.0 3.2.0 wheel requests 2.25.1 2.26.0 wheel setuptools 52.0.0 58.2.0 wheel urllib3 1.26.5 1.26.7 wheel wheel 0.34.2 0.37.0 wheel
To display the information of any package, run the following command:
pip3 show wheel
You should see the information of the wheel package in the following output:
Name: wheel Version: 0.34.2 Summary: A built-package format for Python Home-page: https://github.com/pypa/wheel Author: Daniel Holth Author-email: [email protected] License: MIT Location: /usr/lib/python3/dist-packages Requires: Required-by:
To uninstall any package, run the following command:
pip3 uninstall scrapy
Conclusion
In the above guide, we explained how to install Pip3 and Pip2 on Debian 11. We also explained how to use the Pip command to install and manage Python packages. I hope you can now easily manage the Python dependencies using the Pip command.