pip install: Usage, Options & Common CI Errors
The command you run most in any Python pipeline, with the CI gotchas.
pip install fetches packages from an index (PyPI by default) and installs them into the active environment. It is the workhorse of nearly every Python CI job.
What it does
Resolves and installs one or more packages, plus their dependencies, into the current Python environment. You can pin exact versions, ranges, extras, or install from VCS, local paths, and URLs.
Common usage
Terminal
pip install requests
pip install "requests==2.32.3"
pip install "django>=4.2,<5.0"
pip install "fastapi[all]"
pip install --upgrade pip
pip install "git+https://github.com/psf/requests.git@main"Common CI error: externally-managed-environment
On Debian/Ubuntu runners a bare "pip install" into the system interpreter fails with "error: externally-managed-environment" (PEP 668). Fix it by installing into a virtual environment instead.
Terminal
# Failure on a system Python:
# error: externally-managed-environment
# Fix: create and use a venv
python -m venv .venv
. .venv/bin/activate
pip install requestsOptions
| Option | Does |
|---|---|
| -U, --upgrade | Upgrade to the newest version |
| -t, --target DIR | Install into a specific directory |
| --user | Install to the user site-packages |
| --pre | Allow pre-release versions |
| --no-deps | Skip installing dependencies |
| -i, --index-url URL | Use an alternate package index |
Related guides
pip install -r: Install from requirements.txt in CIHow pip install -r installs every dependency from a requirements file, the flags that make it reproducible in…
pip "Could not find a version that satisfies the requirement"Fix pip "Could not find a version that satisfies the requirement" / "No matching distribution found" in CI -…
python -m venv: Create Virtual EnvironmentsHow python -m venv creates an isolated virtual environment, how to activate it on Linux and Windows runners,…