← Back to Blog

Python on Debian 13: install pip and venv, fix error: externally-managed-environment

Published · by Leo Gashi, RS Computers

Python Debian 13 pip

Debian 13 (trixie) ships Python 3.13.5: on 3 December 2026 the python3 package is 3.13.5-1 and the interpreter behind it, python3.13, is 3.13.5-2+deb13u5. A plain pip install on it stops with error: externally-managed-environment, because Debian marks its Python as managed by apt (PEP 668), and the fix is one of three things: the apt package python3-xyz, a virtual environment made with python3 -m venv, or pipx for command-line tools.

This guide installs pip and venv, shows the full error and what --break-system-packages really does, adds Python 3.14 next to 3.13, and runs an app from a venv under systemd and cron. We ran every command in a fresh Debian 13.8 container on 3 December 2026 and copied the outputs. RS Computers runs KVM servers in Amsterdam, Dublin and Prishtina, and every one of our Linux VPS and VDS plans comes with Debian 13 and full root, so you can follow along on a clean server.

Quick fix for "externally-managed-environment"

# as root
apt update
apt install -y python3-venv python3-pip

# as your normal user, inside the project folder
python3 -m venv .venv
.venv/bin/pip install requests
.venv/bin/python your_script.py

Is it a library Debian already packages? Then apt install python3-requests is shorter. Is it a command-line tool? Then apt install pipx and pipx install toolname.

Key facts, checked on 3 December 2026:

Which Python version does Debian 13 ship?

Ask apt. These commands only read package lists. Run them as root, or put sudo in front:

# as root
apt update
apt-cache policy python3 python3.13 python3-pip python3-venv

Our container answered (trimmed to the first lines of each block):

python3:
  Installed: (none)
  Candidate: 3.13.5-1
     3.13.5-1 500
        500 http://deb.debian.org/debian trixie/main amd64 Packages
python3.13:
  Candidate: 3.13.5-2+deb13u5
     3.13.5-2+deb13u5 500
        500 http://deb.debian.org/debian trixie/main amd64 Packages
python3-pip:
  Candidate: 25.1.1+dfsg-1
python3-venv:
  Candidate: 3.13.5-1

Two version strings appear because Debian splits Python in two. python3 is a small package that says "the default Python 3 on this release" and owns the /usr/bin/python3 symlink. python3.13 is the interpreter itself, and it is the one that receives fixes: +deb13u5 means the fifth update built for Debian 13. Our minimal container image had no Python at all (python3: command not found), so we installed it with apt install -y python3. On a server where python3 --version already answers, skip that.

$ python3 --version
Python 3.13.5
$ python3 -VV
Python 3.13.5 (main, Aug 10 2026, 12:06:59) [GCC 14.2.0]
$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root      10 Jun 30  2025 /usr/bin/python3 -> python3.13
-rwxr-xr-x 1 root root 6832784 Aug 10 12:06 /usr/bin/python3.13
Package on Debian 13Version on 3 Dec 2026What it gives you
python33.13.5-1the python3 command (symlink to python3.13)
python3.133.13.5-2+deb13u5the interpreter and standard library
python3-pip25.1.1+dfsg-1pip, pip3, python3 -m pip
python3-venv3.13.5-1 (pulls python3.13-venv 3.13.5-2+deb13u5)python3 -m venv with pip inside
python3-full3.13.5-1venv plus tkinter, IDLE, gdbm and the test suite
python-is-python33.13.3-1the python command
pipx1.7.1-1one private venv per command-line tool
pyenv2.5.4-1builds other Python versions from source
Python 3.12, 3.14, uvnot in Debian 13see the uv section below

python or python3?

On Debian 13 the command is python3. Typing python gives bash: python: command not found. If a script or a tutorial insists on python, install the symlink package as root:

# as root
apt install -y python-is-python3
ls -l /usr/bin/python
python --version
lrwxrwxrwx 1 root root 7 Apr  9  2025 /usr/bin/python -> python3
Python 3.13.5

Inside an activated venv you never need it: a venv always has its own python.

Install pip and venv on Debian 13

# as root
apt install -y python3-pip python3-venv
pip --version
pip 25.1.1 from /usr/lib/python3/dist-packages/pip (python 3.13)

On our bare container apt reported 0 upgraded, 80 newly installed and After this operation, 419 MB of additional disk space will be used. Most of that is not pip. python3-pip recommends build-essential and python3-dev, the compiler and headers pip needs when a package has no ready-made wheel. If you only want virtual environments, apt install python3-venv alone is enough, because every venv gets its own pip.

The error message tells you to "make sure you have python3-full installed". For a server that is more than you need: on top of what we had, python3-full wanted 29 more packages, among them Tk, IDLE and fonts. python3-venv is the part that matters.

error: externally-managed-environment

Now run what every tutorial tells you to run:

$ pip install requests
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.

    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.

    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

    See /usr/share/doc/python3.13/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

Nothing is broken. pip found the file /usr/lib/python3.13/EXTERNALLY-MANAGED, which belongs to the Debian package libpython3.13-stdlib, and printed the text stored in it. Being root changes nothing, and neither does pip install --user: we ran both as root and got the same error.

Why Debian does this (PEP 668)

Debian's own tools are written in Python and import modules from /usr/lib/python3/dist-packages, which apt fills. If pip writes into the same interpreter, two package managers own the same files and neither knows what the other did. PEP 668 lets a distribution drop a marker file into the standard library folder; when an installer sees it and is not inside a virtual environment, it must stop. The same PEP asks for an override "such as a command-line flag --break-system-packages" that "should carry some connotation that its use is risky". Debian's own advice sits in README.venv.

How to fix externally-managed-environment: four ways, ranked

RankFixUse it forWhere the files go
1apt install python3-xyza library Debian packages, used by system scripts/usr/lib/python3/dist-packages, updated by apt
2python3 -m venvyour own app or project, any version from PyPIthe project's .venv folder
3pipx installcommand-line tools (httpie, uv, ansible and so on)~/.local/share/pipx/venvs, commands in ~/.local/bin
4pip install --break-system-packagesthrowaway containers and CI images only/usr/local/lib/python3.13/dist-packages as root, ~/.local as a user

1. The apt package

# as root
apt install -y python3-requests
python3 -c "import requests; print(requests.__version__, requests.__file__)"
2.32.3 /usr/lib/python3/dist-packages/requests/__init__.py

The package is python3-requests 2.32.3+dfsg-5+deb13u1. It is older than PyPI (a venv on the same day got requests 2.34.2), but Debian patches it and apt upgrade keeps it current.

2. A virtual environment

A venv is a folder with its own python, its own pip and its own packages. We made a normal user and a project folder first, as root: useradd -m -s /bin/bash deploy, then mkdir -p /opt/myapp && chown deploy:deploy /opt/myapp. Then, as that user:

# as deploy
cd /opt/myapp
python3 -m venv .venv
.venv/bin/pip install requests
.venv/bin/python -c "import requests, sys; print(requests.__version__); print(sys.prefix)"
.venv/bin/pip freeze > requirements.txt
Successfully installed certifi-2026.11.20 charset_normalizer-3.5.3 idna-3.20 requests-2.34.2 urllib3-2.8.0
2.34.2
/opt/myapp/.venv

No error, no sudo. The venv was 16 MB. You can call .venv/bin/python and .venv/bin/pip by path, as above, or run source .venv/bin/activate so that python and pip mean the venv's copies until you type deactivate. Services and cron jobs should use the path. To move the app, copy the code and requirements.txt and build a new venv there. More on the module in the Python venv documentation.

3. pipx for command-line tools

# as root
apt install -y pipx

# as deploy
pipx install httpie
pipx ensurepath
  installed package httpie 3.2.4, installed using Python 3.13.5
  These apps are now globally available
    - http
    - httpie
    - https
...
Success! Added /home/deploy/.local/bin to the PATH environment variable.

pipx builds one hidden venv per tool and links the commands into ~/.local/bin. That folder was not on our PATH: right after the install, http gave command not found. pipx ensurepath appends a line to ~/.bashrc, and after logging in again http --version printed 3.2.4. As root, pipx install --global httpie put the commands in /usr/local/bin for all users. Documentation: pipx.pypa.io.

4. What --break-system-packages really does

The flag switches off the PEP 668 check and nothing else. We tested what happens next, as root:

# as root, in a lab container
pip install --break-system-packages flask
python3 -c "import flask; print(flask.__file__)"
Successfully installed blinker-1.9.0 click-8.5.1 flask-3.1.3 itsdangerous-2.2.0 jinja2-3.1.6 markupsafe-3.0.4 werkzeug-3.1.9
/usr/local/lib/python3.13/dist-packages/flask/__init__.py

Three findings from the lab:

When is the flag acceptable? In a container or CI image you throw away after one job, where nothing else uses the system Python, and for a single-user tool installed with --user if you accept the shadowing. Not on a server you keep, and not as a permanent setting: pip config set global.break-system-packages true works (it writes ~/.config/pip/pip.conf) but turns the check off for every future install. For containers, see our Docker on a VPS guide.

To undo it, uninstall with pip and check the folder is empty. Afterwards Python fell back to Debian's copy:

# as root
pip uninstall --break-system-packages -y flask werkzeug jinja2 markupsafe itsdangerous click blinker
ls -A /usr/local/lib/python3.13/dist-packages/
python3 -c "import flask, importlib.metadata as m; print(m.version('flask'), flask.__file__)"
3.1.1 /usr/lib/python3/dist-packages/flask/__init__.py

Install a newer or second Python version on Debian 13

Debian 13 will stay on Python 3.13 for its whole life. For 3.14 or 3.12 next to it, we tested two tools. Do not replace /usr/bin/python3 or point it elsewhere: apt's own Python packages expect 3.13 there.

uv: Python 3.14 in under a second

uv is not in Debian 13, so we installed it with pipx as the deploy user and let it download a ready-built Python:

# as deploy
pipx install uv
uv python install 3.14
python3.14 --version
python3 --version
  installed package uv 0.13.12, installed using Python 3.13.5
Downloading cpython-3.14.10-linux-x86_64-gnu (download) (35.2MiB)
Installed Python 3.14.10 in 829ms
 + cpython-3.14.10-linux-x86_64-gnu (python3.14)
Python 3.14.10
Python 3.13.5

The new interpreter lives under ~/.local/share/uv/python (108 MB) with a python3.14 link in ~/.local/bin. The system python3 is untouched and no root is needed. uv python install 3.12 gave us 3.12.16 the same way in 1.08 s. uv's documentation says these builds come from Astral's python-build-standalone project, because "Python does not publish official distributable binaries" (uv docs). Then make a venv with it:

# as deploy
mkdir -p ~/app314 && cd ~/app314
uv venv --python 3.14
uv pip install requests
.venv/bin/python --version        # Python 3.14.10

Two things surprised us. A venv made by uv venv has no pip inside (.venv/bin/pip: No such file or directory); you install with uv pip install. If you want a classic venv, python3.14 -m venv ~/v314 worked and contained pip 26.3. And uv's Python is marked externally managed too: python3.14 -m pip install requests returned the same error: externally-managed-environment. Same answer: use a venv.

pyenv: builds from source, with two catches on trixie

Debian 13 packages pyenv 2.5.4-1. As root, apt install -y pyenv pulled in 143 packages and 794 MB on our container, because it depends on the compiler and every development library a Python build needs. Two catches:

Pointing pyenv at the home folder fixed it:

# as deploy
export PYENV_ROOT="$HOME/.pyenv"
pyenv install 3.12.9
~/.pyenv/versions/3.12.9/bin/python --version
Installed Python-3.12.9 to /home/deploy/.pyenv/versions/3.12.9
Python 3.12.9

The build took 1 minute 12 seconds with 8 CPU cores and used 313 MB; fewer cores take longer. The result linked against Debian's OpenSSL 3.5.9, and python -m venv worked with it. For newer versions than the package knows, use uv or the upstream pyenv from GitHub, which we did not test.

Debian's python3uv (via pipx)pyenv (apt package)
Versions we got3.13.5 only3.14.10, 3.12.16; list ran from 3.8 to 3.16 alpha3.12.9; list ends at 3.12.9 and 3.13.2
Time to add a versionnot possible0.8 to 1.1 s (download)1 min 12 s on 8 cores (compile)
Extra system packagesnonepipx (6 packages in our lab)143 packages, 794 MB
Security updatesapt, from Debianyou, with uv python install againyou, by rebuilding
Needs rootyes (apt)only to install pipxonly to install pyenv

Run a Python app as a systemd service from a venv

You do not activate a venv in a service. Point ExecStart at the venv's own python and it finds its packages. Our test app, /opt/myapp/app.py, is a small HTTP server on 127.0.0.1:8000 that imports requests from the venv. As root, create the unit:

# as root
cat > /etc/systemd/system/myapp.service <<'EOF'
[Unit]
Description=My Python app (venv)
After=network-online.target
Wants=network-online.target

[Service]
User=deploy
Group=deploy
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/.venv/bin/python /opt/myapp/app.py
Environment=PYTHONUNBUFFERED=1
Restart=on-failure
RestartSec=3
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true

[Install]
WantedBy=multi-user.target
EOF
systemd-analyze verify /etc/systemd/system/myapp.service
systemctl daemon-reload
systemctl enable --now myapp
systemctl is-active myapp
curl -s http://127.0.0.1:8000/
Created symlink '/etc/systemd/system/multi-user.target.wants/myapp.service' → '/etc/systemd/system/myapp.service'.
active
Python 3.13.5, requests 2.34.2, prefix /opt/myapp/.venv

systemd-analyze verify printed nothing, which means no mistakes. PYTHONUNBUFFERED=1 makes print() lines reach journalctl -u myapp at once. Restart=on-failure worked in our test: after kill -9 on the process, the journal showed Scheduled restart job, restart counter is at 1 three seconds later and the app answered again. ProtectHome=true hides /home from the service, which is why the app lives in /opt; drop that line if yours sits in a home folder. Keep the app on 127.0.0.1 behind a web server or a firewall rule; our Debian 13 hardening guide covers the firewall. For AI agents, sizing is in our agent RAM and CPU tests.

Run a venv script from cron

Cron starts jobs with a short PATH and no activated venv, so use the venv's interpreter by full path. As the deploy user, crontab -e and add:

* * * * * /opt/myapp/.venv/bin/python /opt/myapp/job.py >> /home/deploy/job.log 2>&1

After one minute our log held:

2026-12-03T09:55:01 python 3.13.5 requests 2.34.2 exe /opt/myapp/.venv/bin/python

The activate form also ran. We wrote it with a dot rather than source, because cron runs jobs with /bin/sh: cd /opt/myapp && . .venv/bin/activate && python job.py. The schedule fields and the other cron traps are in our crontab guide.

Other Python errors on Debian 13 and their fixes

The virtual environment was not created successfully because ensurepip is not available

Full text from our lab, after python3 -m venv /tmp/v1 without the venv package:

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.13-venv

Fix, as root: apt install -y python3-venv. Then delete the half-made folder and create the venv again. The related message /usr/bin/python3: No module named ensurepip has the same cause and the same fix.

/usr/bin/python3: No module named pip

You ran python3 -m pip and Debian's pip is not installed. Fix, as root: apt install -y python3-pip. A venv has its own pip.

bash: python: command not found

Debian has no python command by default. Use python3, or as root apt install -y python-is-python3. If python3 is missing too, as in our minimal image, apt install -y python3.

bash: pip: command not found

Same story for pip: apt install -y python3-pip as root adds both pip and pip3.

ModuleNotFoundError: No module named 'requests' (in systemd or cron)

The module is in your venv, but the job ran the system Python. We reproduced it twice: with ExecStart=/usr/bin/python3 /opt/myapp/app.py in the unit, and with python3 /opt/myapp/job.py in the crontab. Both logged this error while the same script worked through /opt/myapp/.venv/bin/python. Fix the path to the interpreter; do not install the module system-wide.

error: uninstall-no-record-file

pip was asked to upgrade or remove a module that apt installed. It prints Cannot uninstall requests 2.32.3 and "The package was installed by debian". Upgrade it with apt, or install the newer version in a venv.

How we tested

One system container from the stock Debian 13 image, 2 GB RAM limit, 8 CPU cores visible, on 3 December 2026. /etc/debian_version said 13.8 and the image had no Python installed. Versions seen: python3 3.13.5-1, python3.13 3.13.5-2+deb13u5, python3-pip 25.1.1+dfsg-1, pipx 1.7.1-1, pyenv 2.5.4-1, uv 0.13.12, systemd 257.13-1~deb13u1, cron 3.0pl1-197. Outputs are copied from that session and only shortened.

What we did not test: arm64, Debian 12, upstream pyenv from GitHub, uv's own shell installer, conda, building Python by hand, packages that compile C extensions, and a release upgrade with existing venvs in place.

Frequently asked questions

What Python version does Debian 13 have?

Python 3.13. On 3 December 2026 the python3 package is 3.13.5-1 and python3.13 is 3.13.5-2+deb13u5, and python3 --version prints Python 3.13.5. Debian 13 keeps the 3.13 branch for its whole life and patches it through apt.

How do I fix error: externally-managed-environment on Debian 13?

Do not install into the system Python. Create a virtual environment with python3 -m venv .venv and install with .venv/bin/pip install name. If Debian packages the library, apt install python3-name also works, and for command-line tools use pipx install name.

Is pip install --break-system-packages safe?

It is safe only where the system does not matter, such as a throwaway container. In our test it installed into /usr/local/lib/python3.13/dist-packages, which Python reads before apt's folder, so a later apt version of the same library was installed but never imported.

How do I install pip on Debian 13?

As root, run apt install python3-pip. That gives pip 25.1.1 as pip, pip3 and python3 -m pip. For projects, install python3-venv and use the pip inside each venv.

Can I install Python 3.14 on Debian 13?

Not from Debian's repository, which has only 3.13. In our test, pipx install uv followed by uv python install 3.14 installed Python 3.14.10 into the user's home folder in under a second, next to the system Python 3.13.5.

Do I need to activate a venv in a systemd service or cron job?

No. Call the venv's interpreter by full path, for example /opt/myapp/.venv/bin/python /opt/myapp/app.py. It loads the venv's packages on its own. Our tested unit file and crontab line both work this way.

Does sudo pip install work on Debian 13?

No. Root gets the same externally-managed-environment error, because the marker file /usr/lib/python3.13/EXTERNALLY-MANAGED applies to every user. pip install --user is refused as well.

Sources

Need a hand?

A Python app with a venv and a systemd unit runs well on a small server. Our VPS and VDS plans run on NVMe in Amsterdam, Dublin or Prishtina, with Debian 13, full root and a dedicated IPv4 and IPv6 address, ready in under 60 seconds after payment. VPS plans share vCPUs; if your app compiles packages or works a CPU hard all day, a VDS with dedicated vCPUs is the better fit. Running PHP next to Python? Our PHP on Debian 13 guide is the sister article. If you want the app deployed for you, or a custom setup built around it, we do custom offers quoted per job: write to us on Telegram or by email at info@rscomputers-ks.com.

← All articles

Chat on Telegram