Installing and Using Pip on Debian
Pip is a package management system that simplifies the process of installing and managing software packages written in Python.
You'll often find Python applications that can be installed using PIP. And for that, you need to install PIP first.
This article will show you how to install PIP on Debian and the commands for using PIP to manage Python applications.
Installing Pip3 on Debian 11
Pip or Pi3? Don't panic.
Python used to offer Python versions 2 and 3 simultaneously in previous Debian versions. To distinguish pip in both versions, the package was named pip2 for Python 2 and pip3 for Python 3.
Debian 11 only comes with Python 3 installed by default, so you need to install pip3 here.
First, update the list of available packages:
sudo apt update
Then install the pip3 packages:
sudo apt install python3-pip -y
Pip is now installed on your system. To verify that the installation was successful, check the pip3 version:
pip3 --version
You will see a similar output as below. At this time of writing, the latest stable version is pip20. Your version may differ.
Now you have PIP installed on your system, let's see how to use it.
Search for packages to install with pip
If you want to search for a specific package, you previously could have used the pip search
subcommand.
However, that is no longer an option since this option makes DDOS attacks on the PyPI server easier.
Now, to search for a specific package, you can use the https://pypi.org/search/ site.
For example, if you want to find information about the Django web development framework, go to https://pypi.org/search/ and type django
in the search field and you will see a list of matching packages.
To show all the information about a specific package, run the following command:
pip3 show <package_name>
You will see all the available information about the Django package. This can be useful if you want to learn more about a specific package before you install it on your system.
Installing packages with pip
To install a Python package with PIP, use it in the following fashion
pip3 install <PACKAGE_NAME>
For example, to install Django, run the following command:
pip3 install django
You will see an output similar to below, indicating that Django is installed on your system.
List installed Python packages
To list all installed Python packages, run the following command:
pip3 list
As you can see from the below output, Django is now installed on your system.
Upgrading packages with pip
If there is a newer version of a Python package available in the PyPI repository, you can upgrade to that version using the pip3 install --upgrade subcommand:
pip3 install --upgrade <package_name>
For example, if there is a new version of Django available in the PyPI repository, you can upgrade to that version with the following command:
pip install Django --upgrade
If a package is already up to date, you will see a message similar to below.
The above command additionally upgrades the dependent packages to the newest version. You can use the --upgrade-strategy only-if-needed
flag to prevent this from happening.
pip install --upgrade --upgrade-strategy only-if-needed django
Did you note that I used pip
, not pip3
? In Debian 11, you can use either of the terms and they produce the same result.
Upgrading PIP itself
PIP is a Python package itself and thus it can also be upgraded. To upgrade PIP, run the following command:
pip install --upgrade pip
You will see an output similar to below, indicating that PIP has been successfully upgraded to the latest version.
Uninstalling Packages with Pip3
If you no longer need a Python package that you have installed with PIP, you can uninstall it using the pip3 uninstall
subcommand:
pip3 uninstall <package_name>
For example, to uninstall the Django web development framework, run the following command:
pip3 uninstall django
You will see an output similar to below, indicating that Django has been successfully uninstalled.
Conclusion
As you can see, installing and managing Python packages becomes easy with PIP. You can now use PIP to install the latest versions of Django, Flask, Pyramid, Requests, and many other popular Python packages. To learn more about PIP, check out the official documentation.