Key Points
- Check the Python version on your system using the command line to quickly confirm which interpreter runs by default based on PATH configuration.
- Use the Python interpreter or runtime checks to verify the exact Python version and build details that execute scripts and applications.
- Identify all installed Python versions to resolve conflicts when multiple interpreters exist on the same system.
- Check the Python version inside a virtual environment to confirm that the project runs on the correct isolated interpreter instead of the system default.
- Validate Python version within scripts or applications to prevent automation failures in CI, CD, and scheduled workflows.
Python is widely used for automation, scripting, and application development. Many tools and scripts require a specific Python version to run correctly. If the wrong version is used, issues may arise. This is why checking the Python version on your system before running scripts or tools is important. It helps you avoid compatibility problems and keep your automation reliable.
This guide shows you several ways to check the Python version on your system, including methods from the command line, virtual environment, and scripts.
📌 Recommended deployment strategies:
Click to Choose a Method | 💻 Best for Individual Users | 💻💻💻 Best for Enterprises |
| Method 1: Check Python version using the command line | ✓ | ✓ |
| Method 2: Check Python version from the Python interpreter | ✓ | |
| Method 3: Identify all installed Python versions on the system | ✓ | |
| Method 4: Check Python version inside a virtual environment | ✓ | ✓ |
| Method 5: Check Python version in a script or application | ✓ | ✓ |
Methods to check the Python version on your system
This guide walks you through five ways to check the Python version on your system. Before you start, make sure you meet the requirements below.
📌 General prerequisites:
- Access to the system command line or terminal
- Python installed on the system
- Appropriate permissions to run commands
- Awareness of whether the system uses execution aliases or virtual environments
Method 1: Check Python version using the command line
The command line gives you the fastest way to confirm your Python version. In this method, you check the interpreter your system runs by default based on the current PATH configuration.
Steps:
- Open the command line.
- Windows: Press Win + R to open the Run dialog, type cmd, and click Enter to open the Command Prompt.
- MacOS: Press Command + Space to open Spotlight Search, type Terminal, and click Return.
- Linux: Press Ctrl + Alt + T or open the applications menu and search Terminal, and open it.
- Run the following command:
python --version
- If the command doesn’t return Python 3, run:
python3 --version
- Review the output to identify the installed Python version. It should look like this:
Python 3.11.7
📌 Note: This method shows the Python version linked to your current system PATH. If you have multiple Python versions installed, your system runs the interpreter that appears first in the PATH order.
Method 2: Check Python version from the Python interpreter
Another reliable method is checking the Python version inside Python itself. This method runs the check from an active interpreter session and gives you a more detailed version information, including build and compiler data.
Steps:
- Open the command line.
- Windows: Press Win + R to open the Run dialog, type cmd, and click Enter to open the Command Prompt.
- MacOS: Press Command + Space to open Spotlight Search, type Terminal, and click Return.
- Linux: Press Ctrl + Alt + T or open the applications menu and search Terminal, and open it.
- Start the Python interpreter by running:
python
or, if needed:
python3
- At the Python prompt (>>>), enter:
import sysprint(sys.version)
- Review the output to confirm the Python version and build details.
- Exit the interpreter:
exit()
💡You can also press Ctrl + D on macOS/Linux, or Ctrl + Z then Enter on Windows.
📌 Note: This method shows the version used by the active interpreter session. The result may differ from other installed Python versions on the system.
Method 3: Identify all installed Python versions on the system
If your system has multiple Python installations, this method helps you identify them. It lists every Python interpreter your system can access through the command line. Use this method when you’re resolving version conflicts or when you want to confirm which Python versions are available for your projects.
Steps:
- Open the command line.
- Windows: Press Win + R to open the Run dialog, type cmd, and click Enter to open the Command Prompt.
- MacOS: Press Command + Space to open Spotlight Search, type Terminal, and click Return.
- Linux: Press Ctrl + Alt + T or open the applications menu and search Terminal, and open it.
- On Windows, run:
where python
This command lists all paths where python.exe exists.
- On macOS or Linux, run:
which -a pythonwhich -a python3
This command shows all paths where Python binaries are found.
- Review the list of Python executables and their file paths.
📌 Note: This method lists Python executables resolved through your system PATH. It doesn’t show Python installations that aren’t accessible from the command line.
Method 4: Check Python version inside a virtual environment
Virtual environments isolate dependencies and Python versions per project. When you use a virtual environment, you must check the Python version after activation. This confirms that your project runs on the intended interpreter and not the system default.
Steps:
- Activate the virtual environment.
- Windows (Command Prompt):
.\.venv\Scripts\activate
- Windows (PowerShell):
.\.venv\Scripts\Activate.ps1
- macOS/Linux:
source .venv/bin/activate
- Once the environment is active, check the Python version by running:
python --version
- Review the output to confirm the Python version assigned to the virtual environment.
- Deactivate the environment when you’re done:
deactivate
Method 5: Check Python version within a script or application
Sometimes, you need to confirm the Python version while a script or application is running. This approach works well for automated workflows, CI/CD pipelines, and scripts that rely on specific Python features. You can use it to verify the runtime interpreter before your code runs critical logic.
Steps:
- Add the following lines to your Python script:
import sysprint(sys.version_info)
- Run the script using your intended execution method (command line, scheduler, pipeline, or an application runtime).
- Review the output to confirm the Python version used during execution.
Additional considerations
Keep the following points in mind to avoid confusion and get accurate results when you check Python versions.
Windows execution aliases
On Windows, execution aliases can redirect the python command to the Microsoft Store version instead of your installed interpreter. This can lead to unexpected results when you check the Python version.
You can manage execution aliases through Settings > Apps > App execution aliases, or use the Python launcher (py –version) to confirm which interpreter runs.
Python 2 and Python 3 coexistence
Some systems have both Python 2 and Python 3 installed at the same time. In these cases, the python command may point to Python 2, while python3 points to Python 3.
Virtual environments
Virtual environments isolate Python versions per project. The Python version inside a virtual environment can differ from your global installation.
💡 Activate the environment before checking the Python version to avoid misleading results.
PATH order
Your system PATH controls which Python executable runs by default. If multiple versions are installed, the first entry in PATH takes priority.
Tools requiring python3
Some tools explicitly call python3, even when python exists. This avoids ambiguity and ensures access to Python 3 language features.
Troubleshooting
If you run into issues while checking Python versions, review the common problems below and follow the suggested actions to resolve them.
Python command not found
Python may not be installed, or your system may not be able to locate it. Install Python from python.org or through your package manager. After installation, verify that the installation directory is added to your system PATH.
Wrong version reported
If the reported version isn’t what you expect, Windows execution aliases or PATH order may be redirecting the python command. Check execution alias settings to confirm which interpreter appears first in PATH.
Script fails unexpectedly
When a script fails without a clear cause, the active Python version may not meet its requirements. Make sure the script runs with the intended interpreter and that the required Python version is active at runtime.
Virtual environment mismatch
If version checks return the system Python instead of the project version, the virtual environment may not be active. Activate the environment before running checks or scripts and confirm that the command prompt reflects the active environment.
Multiple versions causing confusion
Standardize Python versions per project or environment. Use python3 for modern projects and consider tools like pyenv on macOS/Linux, or the Python launcher py on Windows.
Using the right methods to check the Python version accurately
Checking the Python version on your system is a simple step, but you should not overlook it. It plays a direct role in keeping automation, scripts, and development workflows stable. You can check the Python version in several ways, such as through the command line, the Python interpreter, or active environments.
Being able to quickly confirm which Python version is installed and running reduces errors and helps you keep systems consistent across users and devices.
Related topics:
