How to Check Python Version
What you’ll build or solve
You’ll identify the exact Python version on your machine and the interpreter path behind it.
When this approach works best
This approach works well when you:
Learn Python on Mimo
- Installed Python and want to confirm the version you got.
- Set up a project and need to confirm your terminal uses the same Python as your IDE or virtual environment.
- Debug a version-related problem, like a syntax error on code that should work in newer Python.
Skip deep version checks when:
- You run everything inside a container or a managed environment that already pins Python for you.
Prerequisites
- A terminal
- macOS/Linux: Terminal
- Windows: PowerShell or Windows Terminal
- No extra tools required. If Python isn’t installed, the first step will make that clear.
Step-by-step instructions
1) Print the Python version from your terminal
Start with the command that most commonly works on your platform.
macOS/Linux:
CSS
python3--version
Windows:
CSS
py--version
What to look for
If you see “command not found” on macOS/Linux or “not recognized” on Windows, your terminal can’t find Python. Jump to Troubleshooting.
2) Confirm which Python executable your terminal is using
The path shows which install you’re running.
macOS/Linux:
Bash
which python3
Windows:
py-c"import sys; print(sys.executable)"
What to look for
If the path points to an unexpected location, your PATH or virtual environment may not be active.
3) Check the version from inside Python
When a tool runs Python for you, ask Python directly. This is especially useful for scripts and CI.
macOS/Linux:
python3-c"import sys; print(sys.version_info)"
Windows:
py-c"import sys; print(sys.version_info)"
What to look for
sys.version_info prints a tuple like (major, minor, micro, ...), which is easy to compare in code.
4) Check the version in a virtual environment
If your project uses a virtual environment, activate it, then check the version again.
macOS/Linux:
Bash
source .venv/bin/activate
python--version
Windows (PowerShell):
CSS
.\.venv\Scripts\Activate.ps1
python--version
If your venv folder uses a different name, replace .venv with the folder you have.
What to look for
- Your prompt often shows something like
(.venv)after activation. - If the version didn’t change as expected, the venv may not be active or may use a different Python.
Quick tip (Windows): py -0 lists Python versions the launcher knows about. This helps when you have multiple installs.
Examples you can copy
Example 1: Quick check for version and path
macOS/Linux:
Bash
python3--version
which python3
Windows:
py--version
py-c"import sys; print(sys.executable)"
Example 2: Guard a script based on Python version
importsys
ifsys.version_info< (3,10):
raiseRuntimeError("This script requires Python 3.10+")
Use this in scripts that rely on newer syntax or standard library features.
Example 3: Confirm a tool is using the Python you expect
Add this to scripts run by your IDE, CI, or automation tools:
Bash
importsys
print("Python:",sys.version_info)
print("Executable:",sys.executable)
Run your normal command and compare the printed executable path with what you expect.
Common mistakes and how to fix them
Mistake 1: Checking python --version on macOS/Linux and getting an unexpected result
What you might do
CSS
python--version
Why it breaks
Some systems don’t map python to Python 3, and some don’t provide python at all.
Fix
Use python3 for checks:
Bash
python3--version
which python3
Mistake 2: Your terminal shows one version, but your IDE runs another
What you might do
Check the version in the terminal, then run the project in your editor and hit version-related errors.
Why it breaks
Your IDE can be configured to use a different interpreter than your terminal.
Fix
Print the interpreter path during the run:
importsys
print(sys.executable)
Then select that same interpreter in your IDE settings, or select your project’s virtual environment interpreter.
Troubleshooting
If you see: python3: command not found (macOS/Linux)
Install Python 3, reopen your terminal, then rerun:
CSS
python3--version
If you see (Windows): py is not recognized
Reinstall Python and select the option to add Python to PATH, then rerun:
CSS
py--version
If you see: Version changes depending on the terminal app
Different shells can load different PATH configs. Check with:
- macOS/Linux:
Bash
which python3
- Windows:
py-c"import sys; print(sys.executable)"
If you see: Your venv activates, but it uses the wrong Python version
Recreate the venv using the Python version you want, then reinstall dependencies.
If you see: Permission errors when running Python from a folder
Move the project to a user-writable directory, then retry.
Quick recap
- Check the version:
python3 --versionon macOS/Linux orpy --versionon Windows. - Check the interpreter path:
which python3orpy -c "import sys; print(sys.executable)". - For scripts and CI, print
sys.version_infofrom inside Python. - If you use a venv, activate it and run
python --versionagain. - On Windows,
py -0shows multiple installed Python versions.
Join 35M+ people learning for free on Mimo
4.8 out of 5 across 1M+ reviews
Check us out on Apple AppStore, Google Play Store, and Trustpilot