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 pytestRelated guides
pip install: Usage, Options & Common CI ErrorsHow pip install works - installing packages, version specifiers, and the options you reach for, plus the CI f…
python -m venv: Create Virtual EnvironmentsHow python -m venv creates an isolated virtual environment, how to activate it on Linux and Windows runners,…
python --version: Check the Active InterpreterHow python --version reports the interpreter version, why CI should verify it before installing, and the vers…