Skip to content
Latchkey

python -m pip: Invoke pip Safely Command Reference

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 environment -- not whichever pip happens to be first on PATH.

Common flags / usage

  • python -m pip install --upgrade pip -- self-upgrade pip
  • python3.12 -m pip install -r requirements.txt -- target a specific Python
  • python -m pip install -e . -- editable install with the right interpreter
  • python -m pip --version -- show pip and the bound interpreter

Example

shell
- uses: actions/setup-python@v5
  with:
    python-version: '3.12'
- run: python -m pip install --upgrade pip
- run: python -m pip install -r requirements.txt

In CI

With several Pythons on a runner, a bare "pip" may belong to a different interpreter than "python", installing packages where your code cannot import them. Always use "python -m pip" with the same interpreter you run tests with.

Key takeaways

  • python -m pip targets the pip belonging to a chosen interpreter.
  • It eliminates the wrong-pip-on-PATH class of CI failures.
  • Use it to upgrade pip before installing dependencies.

Related guides

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