Skip to content
Latchkey

python -m pip: Run pip for the Right Interpreter

The reliable way to invoke pip for a specific Python.

python -m pip runs pip as a module of the interpreter you name, guaranteeing the install lands in that interpreter’s environment - not whichever pip is first on PATH.

What it does

Invokes the pip module belonging to the chosen interpreter. With multiple Pythons installed (common in CI), this removes ambiguity about which environment gets the package.

Common usage

Terminal
python -m pip install --upgrade pip
python3.11 -m pip install -r requirements.txt
python -m pip install -e .

Common CI error: wrong pip on PATH

A bare "pip" may belong to a different interpreter than "python", so packages install where your code can’t import them. Always use "python -m pip" with the same interpreter you run tests with.

Terminal
# Ambiguous - which Python?
# pip install requests

# Explicit:
python -m pip install requests
python -m pytest

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →