Interview Prep/Python for DevOps/Environments, imports & packaging errors

`SyntaxError: invalid syntax` on a line with `match command:` or `X | None` on a server.

BeginnerTroubleshootingEnvironments, imports & packaging errors
Answer

Likely causes → The server runs an older Python than you developed on: match needs 3.10+, X | None in annotations evaluated at runtime needs 3.10+, except* needs 3.11+.

Diagnose →

python3 --version
head -1 script.py      # check the shebang target

Fix → Run with the right interpreter (venv or container), or add from __future__ import annotations for annotation-only usage.

Prevent → Declare requires-python = ">=3.11" and test on the minimum version in CI.

All Python for DevOps questions Roadmap: Python for automation

More on Environments, imports & packaging errors