Skip to content
Latchkey

Wrong Python Version in CI - Pin the Interpreter

Your job is running on a different Python than you think. A newer syntax fails on an old interpreter, or a dependency’s wheel is missing because PATH points at an unexpected version.

What this error means

Code that works locally fails in CI with a SyntaxError for a feature your version supports, or installs the wrong wheels. python --version in CI prints something other than what you intended.

CI log
$ python --version
Python 3.8.10
$ python app.py
  File "app.py", line 10
    match command:
          ^
SyntaxError: invalid syntax

Common causes

The default system Python is older than expected

The runner image’s default python3 may be older than your code requires. Without pinning, you inherit whatever the image ships.

setup-python not used or shadowed

If actions/setup-python is missing, or a later PATH change shadows it, the interpreter in use is not the one you configured.

How to fix it

Pin the interpreter explicitly

.github/workflows/ci.yml
- uses: actions/setup-python@v5
  with:
    python-version: '3.12'
- run: python --version   # assert it's what you expect

Test a matrix of versions

If you support several versions, run them all so a version-specific break is caught.

.github/workflows/ci.yml
strategy:
  matrix:
    python-version: ['3.10', '3.11', '3.12']

How to prevent it

  • Always pin the Python version in CI; never rely on the image default.
  • Add an early python --version assertion step.
  • Declare requires-python so consumers get a clear error on mismatch.

Related guides

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