- Installing and Using Pip on Debian
- Installing Pip3 on Debian 11
- Search for packages to install with pip
- Installing packages with pip
- List installed Python packages
- Upgrading packages with pip
- Upgrading PIP itself
- Uninstalling Packages with Pip3
- Conclusion
- Installing packages using pip and virtual environments¶
- Installing pip¶
- Installing virtualenv¶
- Creating a virtual environment¶
- Activating a virtual environment¶
- Installing pip/setuptools/wheel with Linux Package Managers¶
- Fedora¶
- CentOS/RHEL¶
- openSUSE¶
- Debian/Ubuntu and derivatives¶
- Arch Linux¶
- Table of Contents
- Previous topic
- Next topic
- Navigation
Installing and Using Pip on Debian
Dealing with lots of Python packages? Learn how to install and use PIP for installing and managing Python packages 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
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:
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:
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:
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
For example, to install Django, run the following command:
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:
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:
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:
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:
For example, to uninstall the Django web development framework, run the following command:
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.
Installing packages using pip and virtual environments¶
This guide discusses how to install packages using pip and a virtual environment manager: either venv for Python 3 or virtualenv for Python 2. These are the lowest-level tools for managing Python packages and are recommended if higher-level tools do not suit your needs.
This doc uses the term package to refer to a Distribution Package which is different from an Import Package that which is used to import modules in your Python source code.
Installing pip¶
pip is the reference Python package manager. It’s used to install and update packages. You’ll need to make sure you have the latest version of pip installed.
Debian and most other distributions include a python-pip package; if you want to use the Linux distribution-provided versions of pip, see Installing pip/setuptools/wheel with Linux Package Managers .
You can also install pip yourself to ensure you have the latest version. It’s recommended to use the system pip to bootstrap a user installation of pip:
python3 -m pip install --user --upgrade pip python3 -m pip --version
Afterwards, you should have the latest version of pip installed in your user site:
pip 21.1.3 from $HOME/.local/lib/python3.9/site-packages (python 3.9)
The Python installers for Windows include pip. You can make sure that pip is up-to-date by running:
py -m pip install --upgrade pip py -m pip --version
Afterwards, you should have the latest version of pip:
pip 21.1.3 from c:\python39\lib\site-packages (Python 3.9.4)
Installing virtualenv¶
If you are using Python 3.3 or newer, the venv module is the preferred way to create and manage virtual environments. venv is included in the Python standard library and requires no additional installation. If you are using venv, you may skip this section.
virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.
python3 -m pip install --user virtualenv
py -m pip install --user virtualenv
Creating a virtual environment¶
venv (for Python 3) and virtualenv (for Python 2) allow you to manage separate package installations for different projects. They essentially allow you to create a “virtual” isolated Python installation and install packages into that virtual installation. When you switch projects, you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other environments. It is always recommended to use a virtual environment while developing Python applications.
To create a virtual environment, go to your project’s directory and run venv. If you are using Python 2, replace venv with virtualenv in the below commands.
The second argument is the location to create the virtual environment. Generally, you can just create this in your project and call it env .
venv will create a virtual Python installation in the env folder.
You should exclude your virtual environment directory from your version control system using .gitignore or similar.
Activating a virtual environment¶
Before you can start installing or using packages in your virtual environment you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell’s PATH .
You can confirm you’re in the virtual environment by checking the location of your Python interpreter:
Installing pip/setuptools/wheel with Linux Package Managers¶
This section covers how to install pip , setuptools , and wheel using Linux package managers.
If you’re using a Python that was downloaded from python.org, then this section does not apply. See the Requirements for Installing Packages section instead.
Note that it’s common for the versions of pip , setuptools , and wheel supported by a specific Linux Distribution to be outdated by the time it’s released to the public, and updates generally only occur for security reasons, not for feature updates. For certain Distributions, there are additional repositories that can be enabled to provide newer versions. The repositories we know about are explained below.
Also note that it’s somewhat common for Distributions to apply patches for the sake of security and normalization to their own standards. In some cases, this can lead to bugs or unexpected behaviors that vary from the original unpatched versions. When this is known, we will make note of it below.
Fedora¶
sudo dnf install python3-pip python3-wheel
To learn more about Python in Fedora, please visit the official Fedora docs, Python Classroom or Fedora Loves Python.
CentOS/RHEL¶
CentOS and RHEL don’t offer pip or wheel in their core repositories, although setuptools is installed by default.
To install pip and wheel for the system Python, there are two options:
- Enable the EPEL repository using these instructions. On EPEL 7, you can install pip and wheel like so:
sudo dnf install python3-pip python3-wheel
sudo dnf install python3-pip python3-wheel
sudo dnf upgrade python3-setuptools
To install pip, wheel, and setuptools, in a parallel, non-system environment (using yum) then there are two options:
- Use the “Software Collections” feature to enable a parallel collection that includes pip, setuptools, and wheel.
- For Redhat, see here: https://developers.redhat.com/products/softwarecollections/overview
- For CentOS, see here: https://github.com/sclorg
Be aware that collections may not contain the most recent versions.
sudo yum install python34u python34u-wheel
openSUSE¶
sudo zypper install python3-pip python3-setuptools python3-wheel
Debian/Ubuntu and derivatives¶
Firstly, update and refresh repository lists by running this command:
sudo apt update sudo apt install python3-venv python3-pip
Recent Debian/Ubuntu versions have modified pip to use the “User Scheme” by default, which is a significant behavior change that can be surprising to some users.
Arch Linux¶
Currently, there is no “copr” yum plugin available for CentOS/RHEL, so the only option is to manually place the repo files as described.
Table of Contents
- An Overview of Packaging for Python
- The Packaging Flow
- Tutorials
- Guides
- Installing packages using pip and virtual environments
- Installing stand alone command line tools
- Installing pip/setuptools/wheel with Linux Package Managers
- Installing scientific packages
- Package index mirrors and caches
- Hosting your own simple repository
- Packaging and distributing projects
- Including files in source distributions with MANIFEST.in
- Single-sourcing the package version
- Dropping support for older Python versions
- Packaging binary extensions
- Packaging namespace packages
- Creating and discovering plugins
- Using TestPyPI
- Making a PyPI-friendly README
- Publishing package distribution releases using GitHub Actions CI/CD workflows
- Tool recommendations
- Analyzing PyPI package downloads
Previous topic
Next topic
Navigation
© Copyright 2013–2020, PyPA.
This page is licensed under the Python Software Foundation License Version 2.
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.The Python Software Foundation is a non-profit corporation. Please donate.
Last updated on Jun 16, 2023. Found a bug?
Created using Sphinx 4.5.0.