pip: command not found means pip is not installed for the Python you are using, or it is installed under another name — usually pip3. Install your distribution’s pip package (python3-pip on Debian, Ubuntu, Rocky and Alma, py3-pip on Alpine) and call it as python3 -m pip, which always runs the pip that belongs to python3.
On Debian 12 and later, Ubuntu 23.04 and later, Alpine 3.19 and later and Homebrew on macOS, the very next command then fails with error: externally-managed-environment. That is not a bug. The system Python is protected under PEP 668, and the fix is a virtual environment for projects or pipx for command-line tools. Both are covered below.
# Debian · Ubuntu
sudo apt update && sudo apt install -y python3-pip python3-venv
# Rocky · AlmaLinux · RHEL 9
sudo dnf install -y python3-pip
# Alpine
apk add --no-cache python3 py3-pip
# macOS (Homebrew) — provides pip3, not pip
brew install python
# then, everywhere
python3 -m pip --versionIs pip missing, or only named pip3?
Check what actually exists before installing anything:
command -v pip pip3 # which names are on your PATH
python3 -m pip --version # the pip that belongs to python3
python3 --versionpython3 -m pipworks, barepipdoes not — pip is installed, just not under that name. Usepip3orpython3 -m pip./usr/bin/python3: No module named pip— pip is not installed for that interpreter. Install the package for your distribution below.- python3 itself is not found — Python is missing, not just pip. See python: command not found first.
On current distributions the system package installs both names. Debian 12’s python3-pip ships /usr/bin/pip, pip3 and pip3.11; Ubuntu 22.04 and 24.04 ship pip, pip3 and pip3.10 or pip3.12; Rocky and Alma 9 provide the unversioned pip as well. macOS is the exception — there you get pip3 only, unless you add Homebrew’s unversioned names yourself.
Why python3 -m pip rather than pip: once a machine has more than one Python — the system one, Homebrew, pyenv, a venv — the pip on your PATH can belong to a different interpreter than the python3 that runs your code. Calling pip through the interpreter removes that guesswork.
How do I install pip on Debian and Ubuntu?
sudo apt update
sudo apt install -y python3-pip python3-venv
python3 -m pip --versionInstall python3-venv in the same step — on Debian 12 and Ubuntu 24.04 you will need it a minute later. On Ubuntu, python3-pip, python3-venv and pipx all live in the universe component. If apt answers Unable to locate package python3-pip, run sudo apt update first (fresh images and containers often have no package index at all), then make sure universe is enabled with sudo add-apt-repository universe. If that command is missing too, see add-apt-repository: command not found.
Logged in as root on a minimal image with no sudo at all? Drop the sudo, or see sudo: command not found.
How do I install pip on Rocky Linux, AlmaLinux and RHEL 9?
sudo dnf install -y python3-pip
pip3 --versionThe system Python on EL9 does not carry the PEP 668 marker, so pip will not stop you from running sudo pip install there. That makes it easier to break things, not safer: dnf itself is written in Python and depends on modules in the same directories. Use a virtual environment on Rocky and Alma as well.
How do I install pip on Alpine?
apk add --no-cache python3 py3-pip
python3 -m pip --versionAlpine 3.19 and later mark the system Python as externally managed as well, so a plain pip install in an Alpine container hits the same error as on Debian. Many libraries are packaged as py3-<name>; for anything else, use a venv.
How do I get pip on macOS?
zsh: command not found: pip is the usual macOS form. There are two sources of Python, and neither installs an unversioned pip on your PATH:
- Xcode Command Line Tools (
xcode-select --install) provide/usr/bin/python3and/usr/bin/pip3, an older Python 3 that Apple updates on its own schedule. - Homebrew (
brew install python) providespython3andpip3. Its unversionedpythonandpiplive in a separate directory you can add to your PATH.
brew install python
pip3 --version
# optional: unversioned pip and python, in ~/.zshrc
export PATH="$(brew --prefix python)/libexec/bin:$PATH"
rehashHomebrew’s Python is marked externally managed too, so installing packages into it fails with the same error. Homebrew recommends a venv for project libraries and brew install pipx for tools.
Why do ensurepip and get-pip.py fail on Debian and Ubuntu?
Upstream Python can bootstrap pip with python3 -m ensurepip, and many old guides download get-pip.py. On the system Python of Debian and Ubuntu, both are dead ends:
ensurepipis split out into thepython3.X-venvpackage. Without it, Debian 12 answers/usr/bin/python3: No module named ensurepip. Even with it installed, Debian disables ensurepip for the system interpreter — it is there so thatvenvcan put pip into new environments.get-pip.pyruns into the externally-managed guard on Debian 12+ and Ubuntu 23.04+. On older releases it installs a second pip under/usr/localthat apt does not know about.
The same missing package explains the most confusing variant. Without python3-venv, python3 -m venv prints this on Debian 12:
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.11-venvIt still leaves a half-built directory behind, with a bin/ but no pip in it. Install the package, delete that directory, then create the environment again:
sudo apt install -y python3-venv
rm -rf .venv
python3 -m venv .venvWhat does error: externally-managed-environment mean?
Your distribution has told pip to stay out of the system Python. That is PEP 668: a file named EXTERNALLY-MANAGED in the standard library directory makes pip refuse to install there. On Debian 12 it is /usr/lib/python3.11/EXTERNALLY-MANAGED, owned by the libpython3.11-stdlib package. Ubuntu 24.04 and Debian 13 have it; Ubuntu 22.04 and the EL9 system Python do not. The error on Debian 12 starts like this:
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.
...ls /usr/lib/python3*/EXTERNALLY-MANAGEDThe reason is practical. apt installs Python modules into the system’s site-packages, and so does sudo pip install. When pip upgrades or replaces a module apt depends on, the breakage turns up later — in apt, in unattended-upgrades, in a distribution tool — and not at install time. The fixes, in the order you should reach for them:
1. A virtual environment for your project
sudo apt install -y python3-venv # Debian · Ubuntu only
python3 -m venv ~/.venvs/app
source ~/.venvs/app/bin/activate
pip install requests # pip and python now point into the venv
deactivateInside an active venv, bare pip and python are the venv’s own, and nothing touches the system. For a single project, python3 -m venv .venv in the project directory is the common convention — keep .venv out of git. In cron jobs, systemd units and scripts, skip activate and call the environment’s interpreter directly, e.g. ~/.venvs/app/bin/python app.py.
2. pipx for command-line tools
For applications you want as commands rather than libraries you import, pipx installs each one into its own venv and links the command into ~/.local/bin:
# Debian · Ubuntu
sudo apt install -y pipx
# Rocky · Alma 9 (pipx is in EPEL)
sudo dnf install -y epel-release && sudo dnf install -y pipx
# Alpine
apk add --no-cache pipx
# macOS
brew install pipx
pipx ensurepath # puts ~/.local/bin on your PATH
pipx install httpie # any tool published on PyPI3. The distribution’s own package
For libraries that system scripts need, the distribution often packages them already: sudo apt install python3-requests python3-yaml on Debian and Ubuntu, py3-<name> on Alpine. Names do not always match PyPI — PyYAML is python3-yaml — so search with apt search python3- followed by the name. These are older than PyPI but get security updates with the rest of the system.
4. uv, if you prefer one tool for both
uv, a newer standalone tool from Astral, covers both jobs: uv venv creates environments and uv tool install works like pipx. By default it installs packages only into environments it manages, so the marker does not get in its way. uv is published on PyPI, so pipx install uv gets it without piping an install script into your shell; its documentation lists the other install methods.
Last resort: --break-system-packages
pip install worked, but the command is still not found — why?
pip install --user and pipx put commands into ~/.local/bin. pip even warns that the script was installed in a directory “which is not on PATH”. On Debian and Ubuntu, ~/.profile adds ~/.local/bin to the PATH only if the directory already existed when you logged in, so the first install needs a fresh login — or this:
ls ~/.local/bin # is the command there?
pipx ensurepath # or add it yourself:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc # ~/.zshrc for zsh
hash -r # bash; in zsh: rehashTwo more cases look identical. A command installed inside a venv is only on the PATH while that venv is active — call .venv/bin/<tool> otherwise. And sudo <tool> fails because sudo uses its own restricted PATH, which never includes your ~/.local/bin. The project-local versus global split is the same one Node has; see vite: command not found for that side of it.
Why not just use sudo pip?
sudo pip install writes into the system Python as root. On Debian 12+, Ubuntu 23.04+ and Alpine 3.19+ it is refused anyway. Where it is not refused — Ubuntu 22.04, Rocky and Alma 9 — it mixes pip-managed files into the directories the system package manager relies on. On Debian and Ubuntu those land in /usr/local/lib/python3.X/dist-packages, which is searched before apt’s own directory, so a pip-installed version quietly wins over the apt one for every Python program on the machine. It also runs each package’s build code as root. pip itself prints a warning when it runs as root, for exactly these reasons.
If you use conda, its environments do the same job as a venv — and if the conda command is missing as well, see conda: command not found.
How do I install Python packages in Docker?
The official python images build Python into /usr/local, include pip and carry no externally-managed marker, so pip install works as-is:
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "app.py"]On a debian or ubuntu base, the system Python is protected exactly as it is on a server. A venv inside the image costs two lines and keeps the image honest:
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 python3-venv \
&& rm -rf /var/lib/apt/lists/*
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txtA pip install that stops with nothing but Killed while it builds a large wheel ran out of memory: the kernel’s out-of-memory killer ended it. Add swap or build on a plan with more RAM, then run the install again.
Deploying a discord.py or aiogram bot? Install its packages into a virtual environment as shown above and run it under systemd; bot hosting has the full setup.
Most Python code runs on one core at a time. For compute-heavy scripts that lean on one or two cores, the Hi-CPU KVM line puts fewer vCores per plan on AMD EPYC; for general work and many parallel jobs, Standard KVM carries more vCores per euro.
Another tool missing, or a directory to add to PATH for good in bash, zsh and fish? See command not found: the three causes and the fix for every tool.
Frequently asked
Should I use --break-system-packages?
Only in a throwaway container or VM that nothing else depends on. It lets pip overwrite modules the distribution's package manager installed, and the damage usually shows up later in apt or system tools. A virtual environment ('python3 -m venv') or pipx solves the same problem without that risk.
pip or pip3 — which one should I use?
Prefer 'python3 -m pip'. It always runs the pip that belongs to the python3 you are calling, so packages land in the Python that runs your code. On current Debian, Ubuntu and Rocky the system package installs pip and pip3 as the same program; inside an activated venv, plain pip is correct.
Why is the command still not found after pip install?
'pip install --user' and pipx put commands in ~/.local/bin, which is only on your PATH after a fresh login (Debian and Ubuntu add it in ~/.profile if the directory exists) or after 'pipx ensurepath'. Then run 'hash -r' in bash or 'rehash' in zsh. A command installed inside a venv is only on the PATH while that venv is active.
Do I need sudo for pip?
No. Install into a virtual environment you own, or use pipx — neither needs root. Use sudo only to install the distribution packages (python3-pip, python3-venv, pipx). 'sudo pip install' writes into the system Python and is refused on Debian 12+, Ubuntu 23.04+ and Alpine 3.19+.