pip, Virtual Environments, and Interpreters Cheat Sheet

Use pip correctly across Python versions, venvs, pyenv-style setups, CI, and system interpreters.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Prefer python -m pip

Use pip with Python 3 explicitly

Install a package with a specific interpreter family.

bashANYpython3interpreterbest-practice
bash
python3 -m pip install requests

Safer than calling `pip` directly on systems with multiple Python installs.

Use pip with a specific Python version

Install into Python 3.11 specifically.

bashANYpython-versioninterpreterinstall
bash
python3.11 -m pip install requests

Great when several minor versions are installed side-by-side.

Confirm interpreter path

Print the interpreter path in use.

bashANYinspectinterpreterdebugging
bash
python -c "import sys; print(sys.executable)"

Useful before installing packages so you know where they will land.

venv Workflows

Create venv and install packages

Typical Unix-like local development flow.

bashANYvenvbootstrapdevelopment
bash
python -m venv .venv && source .venv/bin/activate && python -m pip install --upgrade pip

Creates an isolated environment, activates it, and upgrades pip inside it.

Install requirements into an active venv

Install project dependencies after activation.

bashANYvenvrequirementsinstall
bash
python -m pip install -r requirements.txt

Once the venv is active, `python -m pip` targets that environment.

Install to user site packages

Install packages into the user site directory.

bashANYusersite-packagesinstall
bash
python -m pip install --user httpie

Helpful when you cannot write to system site-packages. Avoid inside a venv.

Install despite externally managed environment

Override system package management protections when necessary.

bashANYsystem-pythonsafetyinstall
bash
python -m pip install --break-system-packages requests

Use cautiously. On many Linux distributions, using a venv is safer.

CI and Automation

Upgrade pip, setuptools, and wheel

Bootstrap common packaging tools in CI.

bashANYcibootstrappackaging
bash
python -m pip install --upgrade pip setuptools wheel

A common setup step before building or installing packages in automation.

Run without prompts

Disable interactive prompts for automation.

bashANYautomationcinon-interactive
bash
python -m pip install --no-input -r requirements.txt

Useful in CI systems or scripts where prompts would hang execution.

Disable version check

Skip pip’s self-update version check.

bashANYenvironment-variablesciperformance
bash
PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install -r requirements.txt

Can reduce noise and shave a small amount of time in CI.

Recommended next

No recommendations yet.