Introduction
Pip stands for Preferred Installer Program or Pip Installs Packages. Pip simplifies the installation and management of software packages written in Python. Python's versatility makes it useful not only for a programming language but also for data analysis, AI, and back-end research and development.
In this tutorial, learn how to install Pip for Python 2 & 3 on Debian 9, 10, and 11.
Prerequisites
- A Debian 9, 10, or 11 Linux server.
- User with sudo privileges.
- The apt package manager for Python installation.
Note: Compared to its predecessors, Debian 12 requires a different installation process. If you are using Debian 12, refer to our guide on how to install Pip on Debian 12.
Installing Pip on Debian
The Pip package manager is available for Python 2 and Python 3. The sections below cover the Pip installation for both Python versions on Debian 9, 10, and 11.
Install Pip for Python 2
Follow the sections below to install Pip for your Debian version.
Pip for Python 2 on Debian 9 and Debian 10:
Follow the steps below to install Pip for Python 2 on your Debian 9 or Debian 10 system:
1. Update the packages index:
sudo apt update
2. Install Pip by running the following command:
sudo apt install python-pip
Type Y and press Enter to continue with the installation.
3. Verify Pip installation by running the following command:
pip --version
The output should be similar to the example below, but your version may vary:
Pip for Python 2 on Debian 11
Debian 11 still supports Python 2, but it is considered deprecated as of January 2021. Use Python 2 only for legacy apps and old Python 2 projects. The python-pip package, which provides Pip for Python 2, is no longer available in the official repository and must be installed using a script.
Follow the steps below:
1. Run the following command to download the script for Pip installation:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
2. Make sure that Python 2 is installed on your system. Run:
sudo apt install python
The command installs the necessary packages for Python 2.
3. Install Pip using Python 2 and the script you downloaded earlier. Run the command below:
sudo python2 get-pip.py
The command installs Pip for Python 2 and warns you that Python 2 is no longer supported as of January 2021.
Install Pip for Python 3
The procedure for installing Pip for Python 3 is similar to the one for Python 2. Follow the steps below:
1. Update the packages index:
sudo apt update
2. Install Pip for Python 3 by running the command below:
sudo apt install python3-pip
Type Y to continue and let the process finish.
3. Verify your Python installation with the following command:
pip3 --version
The output should be similar to the example below, but your version may vary:
Now, you are ready to install any package from the Python Package Index.
Using Pip on Debian
Pip is a package manager for Python that allows you to install and manage packages, resolve dependencies, upgrade or remove packages, and much more. This section shows an overview of basic Pip commands to get started using Pip on Debian.
Pip Commands
Once you install Pip, you can test some of the most common Pip commands:
Install Packages
To install a package, use the following syntax:
pip install [package_name]
Uninstall Packages
To uninstall a package, use the syntax below:
pip uninstall [package_name]
Find Packages
To search packages from PyPI, use:
pip search [search_query]
List Installed Packages
To list packages in the current environment, run:
pip list
To list outdated packages, run the following command:
pip list -o
Save Package Information
To redirect the currently installed Python packages and their versions into a file, use the pip freeze
command. Run:
pip freeze > requirements.txt
The command creates a requirements.txt file in your current directory. The file contains a list of all the installed Python packages and their versions. You can use the file for various purposes, such as sharing your project's dependencies with others, setting up a virtual environment with the same package versions, or deploying your project to a server with the specified dependencies.
Pip Third-Party Modules
Python packages are made up of modules (useful code) that expand and augment how Python works. The Python Package Index (PyPI) contains thousands of third-party modules suitable for Python, and the Pip package manager makes the installation of any module a straightforward process.
The users select what they need with the Pip manager, and Python stays compact. Python can always be expanded by downloading the free packages from an ever-evolving repository.
Another Pip's helpful trait is how easy it is to use its command-line functions for installing and managing packages.
Python Virtual Environment
Once you install Pip, you can start exploring Python's Virtual Environment. This feature allows for installing Python modules in a separate area for a given task rather than a global setup. It offers a way to isolate a particular space on your server for a given Python project, with its scripts and a unique set of dependencies that will not overlap with other projects.
There is no limit to the number of Python environments. Each one corresponds to a folder on your Debian server. Setting up these programming environments is a straightforward job with the venv module in the Python 3 library.
Now that Python 3 offers this method of isolating projects on your server, you can keep your system files and your project files distinct and organized. It is a leap ahead for version control while facilitating access to the necessary packages for each Python project.
Note: For other OSes, refer to one of our PIP installation guides:
Conclusion
This guide showed how to install Pip for Python 2 and 3 on Debian 9, 10, and 11. It also listed the most useful Pip commands to get you started using Pip on Debian.
NumPy is a library for the Python programming language with support for large, multi-dimensional arrays and matrices. Check out our guide and learn how to install NumPy using PIP.