pip is the standard package manager for Python. It installs packages from PyPI (Python Package Index) and is essential for any Python development or automation work on Linux. Starting with Debian 12 and Python 3.11+, PEP 668 enforces “externally managed environments” which means you can no longer run sudo pip install system-wide. Virtual environments are now the correct approach.
This guide covers installing pip on Debian 13 (Trixie) and Debian 12 (Bookworm), using virtual environments properly, managing packages with pipx for CLI tools, and the essential pip commands every admin and developer needs.
Prerequisites
- Debian 13 or 12 with sudo access
- Python 3 installed (ships by default on both versions)
Verify Python is available:
$ python3 --version
Python 3.12.x
Step 1: Install pip and venv
sudo apt update
sudo apt install -y python3-pip python3-venv python3-full
The python3-full package pulls in all standard library modules. The python3-venv package provides the venv module for creating isolated environments.
Verify pip:
$ pip3 --version
pip 24.x from /usr/lib/python3/dist-packages/pip (python 3.12)
Step 2: Understand PEP 668 (Externally Managed Environments)
If you try to run pip install system-wide on Debian 12+, you get this error:
$ pip3 install requests
error: externally-managed-environment
This environment is externally managed
To install Python packages system-wide, try apt install python3-xyz
This is intentional. System Python packages are managed by apt, and pip installing over them causes conflicts, broken system tools, and upgrade failures. The fix is not --break-system-packages (despite what some guides suggest). The correct approaches are:
- Virtual environments (venv) – for project dependencies
- pipx – for installing Python CLI tools (ansible, black, cookiecutter, etc.)
- apt – for system-level Python packages (
apt install python3-requests)
Step 3: Use Virtual Environments (Recommended)
A virtual environment is an isolated Python installation where you can install any packages without affecting the system. Create one per project.
# Create a virtual environment
python3 -m venv ~/myproject/venv
# Activate it
source ~/myproject/venv/bin/activate
# Your prompt changes to show the active venv
(venv) $ pip install requests flask sqlalchemy
(venv) $ pip list
Package Version
------------ -------
Flask 3.1.x
requests 2.32.x
SQLAlchemy 2.0.x
# Deactivate when done
(venv) $ deactivate
Inside an active venv, pip install works without sudo and without the PEP 668 error. Each venv is self-contained – deleting the folder removes everything cleanly.
Freeze and reproduce dependencies
# Save current packages to requirements.txt
(venv) $ pip freeze > requirements.txt
# On another machine or fresh venv, install from the file
pip install -r requirements.txt
Step 4: Install pipx for CLI Tools
pipx installs Python command-line applications in isolated environments automatically. Each tool gets its own venv but the commands are available globally. This is the right way to install tools like ansible, black, httpie, cookiecutter, or youtube-dl.
sudo apt install -y pipx
pipx ensurepath
Restart your shell or run source ~/.bashrc, then install tools:
# Install Ansible
pipx install ansible-core
# Install black (code formatter)
pipx install black
# Install httpie (modern curl alternative)
pipx install httpie
# List installed tools
$ pipx list
package ansible-core 2.17.x
- ansible
- ansible-config
- ansible-playbook
package black 24.x
- black
package httpie 3.x
- http
- https
Upgrade a pipx-installed tool:
pipx upgrade ansible-core
pipx upgrade-all # Upgrade everything
Step 5: Essential pip Commands
These commands work inside a virtual environment or with pipx:
| Command | Description |
|---|---|
pip install flask | Install a package |
pip install flask==3.0.0 | Install a specific version |
pip install -U flask | Upgrade a package |
pip uninstall flask | Remove a package |
pip list | List all installed packages |
pip list --outdated | Show packages with updates available |
pip show flask | Show package details (version, location, deps) |
pip freeze > requirements.txt | Export installed packages |
pip install -r requirements.txt | Install from requirements file |
pip cache purge | Clear pip download cache |
Step 6: Configure pip (Optional)
Create a pip config file for persistent settings like custom index URLs or trusted hosts (useful behind corporate proxies):
mkdir -p ~/.config/pip
cat > ~/.config/pip/pip.conf << 'CONF'
[global]
timeout = 30
index-url = https://pypi.org/simple/
trusted-host = pypi.org
[install]
# Cache packages locally
cache-dir = ~/.cache/pip
CONF
For a private PyPI mirror (Nexus, Artifactory, devpi):
[global]
index-url = https://nexus.internal.com/repository/pypi-all/simple/
trusted-host = nexus.internal.com
When to Use pip vs apt for Python Packages
| Scenario | Use | Why |
|---|---|---|
| System tools (ansible for root) | apt install ansible | Managed by Debian, gets security updates |
| CLI tools for your user | pipx install ansible-core | Isolated, latest version, no conflicts |
| Project dependencies | pip install in venv | Isolated per project, reproducible |
| System library (e.g. python3-apt) | apt install python3-apt | Only available via apt, ties into system |
| Latest bleeding-edge version | pip install in venv | PyPI has newest releases before apt |
Troubleshooting
"externally-managed-environment" error:
Use a venv: python3 -m venv myenv && source myenv/bin/activate && pip install package. Do not use --break-system-packages unless you fully understand the consequences.
pip3 command not found:
sudo apt install python3-pip
"No module named venv" error:
sudo apt install python3-venv
pip install fails with SSL certificate error:
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org package-name
Or fix the system certificates: sudo apt install ca-certificates && sudo update-ca-certificates
Permission denied when pip installing:
You're not in a venv. Activate one first, or use --user flag: pip install --user package-name
Conclusion
On modern Debian, the days of sudo pip install are over. Use virtual environments for project work, pipx for CLI tools, and apt for system packages. This approach prevents dependency conflicts and keeps your system stable across upgrades.
Related guides:
- Install Python 3.13 on RHEL 10 / Rocky Linux 10 / AlmaLinux 10
- Install Deno on RHEL / Ubuntu
- Install Django on Debian Linux





























































Pip for Python 2 seems to be no longer available in Debian 11/bullseye
Package python-pip is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
python3-pip
Yes Debian 11 seems to be on Python 3 full throttle 🙂