Skip to content
Latchkey

pip install: Command Reference for CI

The package install command at the heart of nearly every Python CI job.

pip install fetches packages from an index (PyPI by default) and installs them into the active environment. This page covers the flags and CI patterns you reach for most.

Common flags / usage

  • pkg or pkg==1.2.3 -- install latest, or pin an exact version
  • -U, --upgrade -- upgrade to the newest allowed version
  • --no-cache-dir -- skip the wheel cache (smaller Docker layers)
  • --no-deps -- install only the named package, not its dependencies
  • --pre -- allow pre-release versions
  • -i, --index-url URL -- install from an alternate index

Example

shell
- uses: actions/setup-python@v5
  with:
    python-version: '3.12'
    cache: 'pip'
- run: python -m pip install --upgrade pip
- run: pip install "requests==2.32.3" "django>=4.2,<5.0"

In CI

On Debian/Ubuntu runners, installing into the system interpreter fails with "externally-managed-environment" (PEP 668); install into a venv instead. Let setup-python cache the pip directory, and use --no-cache-dir only inside Dockerfiles where a persisted cache is not reused.

Key takeaways

  • pip install resolves and installs a package plus its dependencies into the active environment.
  • Pin versions (pkg==1.2.3) for reproducible CI builds.
  • Cache the pip directory across runs; reserve --no-cache-dir for Docker image builds.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →