Last Updated :
22 Apr, 2025
Python has multiple versions, and it’s important to know which version is installed on your system. This information is crucial because different Python versions may have variations in syntax or libraries, and ensuring you’re using the correct version is vital for compatibility with your projects. In this guide, we’ll explore various straightforward methods on how to check the Python version on your Linux, Windows, and Mac systems.
How to Check Python Version on Windows and Mac
To check the Python version on Windows or Mac system, we can follow these methods:
- Using the Command Prompt/Terminal
- Checking in the Interactive Shell
Using the Command Prompt/Terminal
Open the Command Prompt for Windows by searching for “cmd” in the Windows Start menu or open Terminal for Mac by searching Terminal in the MacOS spotlight search. Then, use one of the following commands:
For Python 2:
python –version
or
python -V
For Python 3:
python3 –version
or
python3 -V
python Version using Command Prompt
Using Interactive Shell
We can also find the Python version in the interactive shell. Open the Command Prompt/terminal and enter one of the following commands:
For Python 2:
python
For Python 3:
python3
Once you are in the Python interactive shell, you can check the version with these Python commands:
import sys
print(sys.version)
Python Version Using Interactive Shell
How to Check Python Version on Linux
We can use the following methods to check the Python version on Linux systems like Ubuntu, Debian, Arch, etc. These methods can be used to find Python version:
- Using the Command Line
- Checking in the Interactive Shell
- Using Package Managers
- Checking the Path
Check the Python Version Using the Command Line
The command line provides a straightforward way to get the Python version. Open your terminal and use this simple check Python version command:
For Python 2:
python –version
or
python -V
For Python 3:
python3 –version
or
python -V
Check Python Version Using the Command Line
NOTE: These commands will display the Python version installed on your Linux system.
Check Python Version Using Interactive Shell
Python’s interactive shell is another way to find Python version. Open your terminal and enter one of the following commands:
For Python 2:
python
For Python 3:
python3
Once you are in the Python interactive shell, you can get Python version with the following Python commands:
import sys
print(sys.version)
Checking Python Version in the Interactive Shell
Check Python Version Using Package Managers
If you installed Python using a package manager, you can use these tools to check the Python version.
For Debian-based systems, such as Ubuntu, you can use `apt`:
apt show python3
Check Python Version Using Package Managers
For Red Hat-based systems, like CentOS, you can use yum:
yum info python3
NOTE: These commands will provide detailed information about the Python version installed on your system.
Finding Python Version by Checking the Path
We can also determine the path to the Python interpreter and indirectly obtain information about the installed version using the `which` command:
which python3
This command will return the path to the Python interpreter. We can then use this path to check the version:
/path/to/python –version
Replace ‘/path/to/python’ with the actual path obtained from the previous which command.
Finding Python Version by Checking the Path
Also Read:
- Download and Install Python 3 Latest Version
- How to update Python on Windows?
- How to Download and Install Python Latest Version on Linux
Пройдите тест, узнайте какой профессии подходите
Очень важно знать, какая версия Python установлена на вашем компьютере, особенно если вы работаете над проектом, который требует определенной версии.
Очень важно знать, какая версия Python установлена на вашем компьютере, особенно если вы работаете над проектом, который требует определенной версии. Версия Python может влиять на работу кода, так как разные версии могут иметь различные функции и библиотеки. Например, у вас может быть установлена версия Python 2.7, но вы хотите использовать функции, доступные только в Python 3.6. В этом случае вам нужно будет обновить Python до версии 3.6.
Освойте Python на курсе от Skypro. Вас ждут 400 часов обучения и практики (достаточно десяти часов в неделю), подготовка проектов для портфолио, индивидуальная проверка домашних заданий и помощь опытных наставников. Получится, даже если у вас нет опыта в IT.
Узнайте свою версию Python
Есть несколько способов узнать версию Python на вашем компьютере. Но самый простой и надежный из них — это использовать командную строку.
Для пользователей Windows
Откройте командную строку, нажав клавиши Windows + R
, затем введите cmd
и нажмите Enter
.
В командной строке введите python --version
и нажмите Enter
. Система должна показать версию Python, установленную на вашем компьютере.
Для пользователей MacOS и Linux
Откройте Терминал.
В терминале введите python3 --version
и нажмите Enter
. Система должна показать версию Python, установленную на вашем компьютере.
На курсе Skypro «Python-разработчик» освоите основные инструменты программирования, получите опыт на реальных проектах и сможете стартовать в профессии уверенным новичком. Преподаватели — практикующие программисты с большим опытом, а в центре карьеры помогут составить цепляющее резюме и подготовиться к собеседованию.
Обновление Python
Если вы хотите обновить свою версию Python, вы можете скачать последнюю версию с официального сайта Python. Помните, что обновление Python может повлиять на некоторые из ваших существующих проектов, которые зависят от старых версий Python. Поэтому всегда рекомендуется создать резервную копию ваших проектов перед обновлением Python.
В любом случае, знание версии Python на вашем компьютере поможет вам писать более эффективный код и избегать проблем совместимости.
By Shittu Olumide
Python is a versatile and widely used programming language known for its simplicity and readability.
With its ever-evolving nature, different versions of Python are often released, each offering new features, enhancements, and bug fixes.
As a Python developer, it is crucial to be aware of the Python version you are using, as it determines the compatibility of libraries, syntax, and functionalities.
In this article, we will explore various methods to check the Python version installed on your system. Whether you are a beginner starting your Python journey or an experienced developer working on a project, knowing your Python version is the first step towards ensuring smooth execution and compatibility.
We will dive into the command-line approaches to determine the Python version. By the end of this article, you will be equipped with the knowledge to effortlessly check your Python version and make informed decisions regarding the tools and libraries you can utilize.
To check the Python version on a Mac, you can follow these steps:
Open the Terminal application on your Mac:
You can find the terminal by navigating to «Applications» -> «Utilities» -> «Terminal«, or by using Spotlight search (Cmd + Space) and typing «Terminal«.
Once the Terminal is open, you will see a command prompt where you can enter commands. Type the following command and press Enter:
python --version
This command will display the Python version installed on your Mac. For example, if you have Python 3.9.2 installed, it will display something like:
Python 3.9.2
The version number will vary depending on the specific Python installation on your system.
Alternative methods for Mac
If the python --version
command does not work, try using the python3
command instead. Python 3 is the latest major version of Python, and some systems have both Python 2 and Python 3 installed.
To check the Python 3 version, enter the following command and press Enter:
python3 --version
This command will display the Python 3 version installed on your Mac.
Another way to check the Python version is by using the sys
module within the Python interpreter. In the Terminal, type the following command and press Enter to start the Python interpreter:
python
This will launch the Python interpreter, and you will see a new prompt (>>>
) indicating that you can enter Python commands.
Within the Python interpreter, type the following command and press Enter:
import sys
print(sys.version)
This will print the detailed Python version information, including the version number and additional details such as the build number and the date of the Python installation.
After checking the Python version, you can exit the Python interpreter by typing exit()
and pressing Enter, or by pressing Ctrl + Z followed by Enter.
By following these steps, you will be able to check the Python version installed on your Mac using the Terminal application.
How to Check Python Version in Windows
To check the Python version on a Windows operating system, you can follow these detailed steps:
Open the Command Prompt:
- Press the Windows key on your keyboard.
- Type «cmd» (without quotes) in the search bar.
- Click on the «Command Prompt» app from the search results. This will open the Command Prompt window.
Check if Python is installed:
In the Command Prompt window, type the following command and press Enter:
python --version
If Python is installed on your system, it will display the version number. For example, «Python 3.9.2«.
If Python is not installed, you will see an error message stating that the command is not recognized. In this case, you need to install Python before proceeding.
Verify the Python installation location (optional):
In the Command Prompt, type the following command and press Enter:
where python
This command will display the path of the Python executable file. By default, Python is installed in the «C:\PythonXX» directory, where «XX» represents the version number.
If the command doesn’t return any result, it means Python is not installed or not added to the system’s PATH environment variable.
Check the Python version using the Python interpreter:
In the Command Prompt, type the following command and press Enter:
python
This will launch the Python interpreter, displaying the Python version information at the top. For example, «Python 3.9.2 (tags/v3.9.2:1a79785, Feb 22 2021, 12:26:58)«.
To exit the Python interpreter, you can type exit()
and press Enter.
Check the Python version using IDLE (optional):
IDLE is an integrated development environment that comes bundled with Python.
In the Command Prompt, type the following command and press Enter:
idle
This will launch the IDLE Python Shell, which will display the Python version information at the top. For example, «Python 3.9.2 (tags/v3.9.2:1a79785, Feb 22 2021, 12:26:58)«.
To exit the IDLE Python Shell, you can go to the «File» menu and choose «Exit» or simply close the window.
By following these steps, you can easily check the Python version installed on your Windows system using the Command Prompt or Python interpreter.
How to Check Python Version in Linux
Open a terminal:
Launch the terminal application on your Linux system. You can typically find it in the applications menu or by using a keyboard shortcut such as Ctrl+Alt+T.
In the terminal, type the following command and press Enter:
python --version
This command will display the Python version installed on your system.
Note: Some Linux distributions, such as Ubuntu, may have both Python 2 and Python 3 installed. In that case, the above command may display the version of Python 2. To check the version of Python 3, you can use the following command:
python3 --version
Check the output:
After executing the command, the terminal will display the Python version installed on your system. It will typically be in the format «Python x.y.z», where x, y, and z represent the major, minor, and micro versions respectively.
For example, the output might be:
Python 3.9.2
This means Python version 3.9.2 is installed on your Linux system.
### Verify the installation:
To verify that the Python version displayed is correct, you can also enter the Python interactive shell by typing the following command and pressing Enter:
```bash
python
This will open the Python shell, where you can interactively execute Python commands.
Check the version from the Python shell:
In the Python shell, you can confirm the version by typing the following command and pressing Enter:
import sys
print(sys.version)
The output will display detailed information about the Python version, including the version number, build information, and additional details.
Exit the Python shell
To exit the Python shell, you can type exit()
or press Ctrl+D.
By following these steps, you can easily check the Python version installed on your Linux system.
Conclusion
By following the instructions provided in this article, you can easily check your Python version whether you use Mac, Windows, or Linux. This will help you write your Python programs confidently.
Remember to consult the relevant documentation or community resources if you encounter any issues or if you are using non-standard Python distributions or virtual environments.
As Python continues to evolve, staying updated with the installed Python version becomes increasingly important. This knowledge lets you to take advantage of new features and improvements introduced in newer Python releases while ensuring compatibility with existing codebases.
Let’s connect on Twitter and on LinkedIn. You can also subscribe to my YouTube channel.
Happy Coding!
Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started
-
Если ее нет на панели задач, щелкните по значку лупы у
или нажмите ⊞ Win+S.
-
Откроются результаты поиска.
-
Откроется черное окно командной строки с приглашением Python.
-
В левом верхнем углу окна отобразится слово «Python», а справа от него — версия Python (например, 2.7.14).
Реклама
-
Для этого откройте окно Finder и нажмите «Программы» > «Утилиты» > «Терминал».
-
-
Версия Python отобразится под словом «Python» (например, 2.7.3).
Реклама
Об этой статье
Эту страницу просматривали 68 314 раз.
Была ли эта статья полезной?
In this tutorial, you’ll learn how to check your Python version in Windows, macOS, and Linux. You’ll learn how to check the version of Python using the command line and within a Python script itself. You’ll learn how to get the version number of the interpreter that your scripts will use.
Knowing how to do this is an important skill for any Python developer. For example, it can be an important skill in order to better troubleshoot your code. If your interpreter is set to a different version than you’re expecting (say, Python 2 versus Python 3), being able to identify the version of the interpreter can help troubleshoot your problems.
By the end of this tutorial, you’ll have learned:
- How to check the Python version of your interpreter in Windows, Mac OS, and Linux
- How the check the Python version while running your script
- How to access the major, minor and micro versions of your Python version programmatically
Let’s get started!
Table of Contents
To check the version that your Python interpreter is running we can use a version command on the python
command. Because accessing the command line prompt or terminal varies from system to system, this part of the tutorial is split across the different operating systems available to you.
Over the following sections, you’ll learn how to check your Python version using Windows 10, Windows 7, macOS, and Linux.
How to Check Your Python Version on Windows 10
In Windows 10, we can use the PowerShell to check the version of Python that we are running. In order to access the PowerShell, simply use the following steps:
- Press
Windows + R
- Type powershell
- Press
OK
or hitenter
Once the PowerShell is open you can access the Python version your interpreter is running by writing the commands shown below.
Command | Description | Sample Output |
---|---|---|
python --version |
Shortened information about Python version | Python 3.8.5 |
python -V |
Shortened information about Python version | Python 3.8.5 |
python -VV |
Extended information about the Python version | Python 3.8.5 (default, Sep 4 2020, 02:22:02) |
How to Check Your Python Version on Windows 7
On Windows 7 and earlier, you can use the command prompt to check your Python version. In order to do this, you can run the following steps:
- Press
Windows
+R
- Type
cmd
- Press
OK
or hitenter
Check the table below for the different types of commands you can run in order to check your version of Pyhton on Windows 7:
Command | Description | Sample Output |
---|---|---|
python --version |
Shortened information about Python version | Python 3.8.5 |
python -V |
Shortened information about Python version | Python 3.8.5 |
python -VV |
Extended information about the Python version | Python 3.8.5 (default, Sep 4 2020, 02:22:02) |
In the next section, you’ll learn how to check your Python version on macOS or Linux.
How to Check Your Python Version on macOS / Linux
In macOS and Linux you can use the Terminal application to check your version of Python. On macOS, this can be accomplished by following the steps below:
- Open Spotlight by hitting
command
+space
- Type in Terminal and hit
enter
Because some versions of macOS come with Python 2 installed by default, it’s likely that the python
command may refer to Python 2. Because of this, you may need to run python3
instead, to refer to that version of Python.
The table below breaks down the different commands to run on macOS and Linux to get the version of Python:
Command | Description | Sample Output |
---|---|---|
python3 --version |
Shortened information about Python version | Python 3.8.5 |
python3 -V |
Shortened information about Python version | Python 3.8.5 |
python3 -VV |
Extended information about the Python version | Python 3.8.5 (default, Sep 4 2020, 02:22:02) |
python --version |
Shortened information about Python version | Python 2.7.18 |
python -V |
Shortened information about Python version | Python 2.7.18 |
In the next sections, you’ll learn how to check the version of Python your code is running in your script using the sys
and platform
libraries.
How to Check Your Python Version in a Script Using sys
The sys
library provides a number of different ways in which you can access the version of Python you’re running.
One of the simplest ways is to simply print out the .version
attribute. This returns the same information as the -VV
command shown above. Let’s take a look:
# Checking the Python Version Using the sys library
import sys
print(sys.version)
# Returns:
# 3.8.5 (default, Sep 4 2020, 02:22:02)
# [Clang 10.0.0 ]
Because this returns a multi-line string, it’s not immediately accessible. For example, if you wanted to check whether or not a script is running in Python 3.6 or later (to make use of f-strings, for example), you’d have a hard time parsing this.
Instead of using the .version
attribute, we can use the .python_version
attribute to make this process better. It returns a named tuple that provides all the information in an easy to access manner.
The tuple returned has the following attributes: (major, minor, micro, releaselevel, serial)
. Let’s see how we can check the major and minor version to see if we can use Python f-strings:
# Checking the Python Version Number Programatically
import sys
if sys.version_info.major == 3 and sys.version_info.minor >= 6:
print(f'You are running Python {sys.version_info.major}.{sys.version_info.minor}!')
else:
print('Sadly, no f-strings!')
# Returns:
# You are running Python 3.8!
In the code above we checked if our system was capable of running Python f-strings. In the next section, you’ll learn how to use the platform
library to check your Python version.
How to Check Your Python Version in a Script Using platform
The Python platform
library provides a number of helpful methods that are very similar to the ones provided by the sys
library. For example, the python_version()
function can be used to return a string that contains the Python version.
Let’s see how we can import the library and return a string containing our current Python version:
# Checking Your Python Version with platform
import platform
print(platform.python_version())
# Returns: 3.8.5
Similar to the sys
library, the platform
library provides a way to extract a tuple. Unlike the sys
library, the tuple that’s returned is not a named tuple and each item in the tuple is a string, not an integer. Let’s take a look at an example:
# Checking Your Python Version with platform
import platform
print(platform.python_version_tuple())
# Returns: ('3', '8', '5')
Conclusion
In this tutorial, you learned how to check your version of Python on Windows, macOS and Linux. You also learned how to check the version your code is running in your script using both the sys
and platform
library. Being able to check the version of Python you’re using allows you to better troubleshoot your code and identify any problems that are caused by versions.
Additional Resources
To learn more about related topics, check out the tutorials below:
- Use Python to List Files in a Directory (Folder) with os and glob
- How to Read a Text File in Python (Python open)
- Python: Check if a File or Directory Exists
- Python: Copy a File (4 Different Ways)
- Python sys Official Documentation