Python is a versatile, powerful programming language with many applications, from web development to data analysis. Most often when programming in Python, you’ll want to know which version of Python you are using.
You can check your Python version quickly and effortlessly using multiple methods, imncluding command-line tools, running a script with the platform and sys modules, or within your preferred IDE.
These approaches are applicable across different operating systems, including Windows, macOS, and Linux, ensuring you can identify your Python version in no time.
Each new version of Python comes with certain changes or updates, therefore, code written previously in another version might not work in the newer versions.
Different versions of Python can have subtle differences and knowing the exact version you’re working with can help you avoid compatibility issues when sharing code with others or installing packages.
In this article, we’ll provide a straightforward guide on how to check the Python version on your computer, whether you’re using Windows, macOS, or Linux.
Let’s get into it!
How to Check Python Version from the Command Line
In this section, we’ll discuss how to check Python version using the command line. This method is quick and effective for determining which version of Python is installed on your computer.
Specifically, we will cover the following:
-
How to check Python version in Windows
-
How to check Python version in Linux
-
How to check Python version in MacOS
Let’s get into it!
Windows Command Line Prompt
Before you proceed with this procedure, make sure that have Python installed. To check your Python-installed version on a Windows machine using the Command Line Prompt, follow these steps:
Step 1: Press Win+R to open the Run dialog.
Step 2: Type cmd and press Enter to open the Windows Command Prompt.
Step 3: In the Command Prompt, type python –version and press Enter.
The above prompt will command Python display the installed Python version. If you don’t see a response or encounter an error, ensure that Python is installed and added to your environment variables.
MacOS and Linux Terminal
On Linux and macOS systems, you can use the Terminal to check your Python version.
Follow these instructions:
Step 1: For Linux, press Ctrl+Alt+T to open the Terminal. For macOS, go to Finder, click on Applications, choose Utilities, and then select Terminal.
Step 2: Once the Terminal is open, type python –version and press Enter.
The above prompt will command Python to show your current version of Python installed.
If you have multiple Python versions installed on your computer, you may need to use python3 –version to check the version of Python 3.
Now that you know how to check your version from the command line, you can ensure you’re using the correct version for your projects and manage your environment accordingly.
The above was just one way of checking the Python version running on your computer. You can also check the version from a Python script. The section below demonstrates how to check the version using a Python script.
How to Check Python Version from a Script
In this section, you’ll learn how to check the Python version from within a script using different modules.
We will explore the following:
-
How to check Python version using the sys Module
-
How to check Python version using the platform Module
This will help you ensure your script runs on the desired version and adapt its behavior based on the version being used.
How to Check Python Version Using The Sys Module
One way to check the Python version from a script is by using the sys module.
The sys module in Python, which is an integral part of its standard library, gives you the ability to tap into various variables, functions, and objects that are either used or maintained by the interpreter.
By doing so, you can engage with the system and the Python runtime environment, taking advantage of a range of features that prove helpful for tasks related to the system, debugging, or managing the execution of your Python scripts.
The sys module provides the version_info attribute, which contains a tuple with the major, minor, and micro version numbers of the Python interpreter.
The code provided below uses the sys module to check the Python version:
import sys
major, minor, micro = sys.version_info[:3]
print(f"Your Python version is {major}.{minor}.{micro}")
This above code will command Python to import sys print module and use it to retrieve the version of Python.
import sys: This line imports the sys module, which provides access to system-specific parameters and functions.
major, minor, micro = sys.version_info[:3]: The sys.version_info attribute returns a tuple containing the components of the Python version, such as major, minor, and micro version numbers.
Here, we are slicing the tuple with [:3] to get the first three elements, which represent the major, minor, and micro version numbers, and assigning them to the respective variables major, minor, and micro.
print(f”Your Python version is {major}.{minor}.{micro}”): This line uses an f-string (formatted string literal) to display the Python version by substituting the values of major, minor, and micro variables in the string.
The output of import sys print will show the Python version in the format “Your Python version is X.Y.Z”, where X, Y, and Z are the major, micro, and minor version numbers, respectively.
Keep in mind that at times, you might have multiple versions of Python installed and the out will display the most latest Python version.
In addition, you can use an assert statement to make sure your script runs on a minimum required Python version. For example:
import sys
assert sys.version_info >= (3, 6), "Python 3.6 or higher is required"
The above Python code snippet demonstrates how to import the sys module and use it to check if the Python version is 3.6 or higher. If the requirement is not met, an AssertionError with a custom message is raised.
How to Check The Version of Python Installed Using the Platform Module
Another way to check the Python version is by using the platform module Python command.
The platform module in Python is part of the standard library and provides various functions to retrieve information about the underlying platform, system, and hardware on which the Python interpreter is running.
This can include details about the operating system, processor architecture, and the Python implementation itself.
The import platform print provides the python_version() function, which returns a string with the Python version.
Here’s a sample code demonstrating how to use the platform module:
import platform
version = platform.python_version()
print(f"Your Python version is {version}")
The above Python code snippet demonstrates how to import the platform print module and use it to retrieve the Python version information, then print it in a formatted string.
You can also use the Python command below which uses tuples to check the Python version:
import platform
version_tuple = platform.python_version_tuple()
print("Your Python version is {}.{}.{}".format(*version_tuple))
Both the sys and platform modules provide various Python commands to obtain information about the Python environment, and you can choose the one that better fits your specific use case or requirements.
Most often, programmers use IDEs for writing code. You can check the major version in your IDE as well.
In the section below, we will explore how to check Python version in two of the most popular IDEs for Python programming: VSCode and PyCharm.
How to check Python Version in Integrated Development Environments (IDE)
An Integrated Development Environment is a software application that offers a comprehensive set of tools and features to help programmers write, edit, debug, and compile code more efficiently.
Checking the Python versions in an Integrated Development Environment (IDE) is a common task when working on Python projects. Each IDE has its own way of displaying the Python version. In this section, we will discuss the following:
-
How to check Python version in Visual Studio Code
-
How to check Python version in PyCharm
How to check Python versions in Visual Studio Code
Visual Studio Code (VSCode) is a popular IDE for Python development. To check the Python version in VSCode, follow these steps:
Step 1: Open Visual Studio Code.
Step 2: Open a Python file or create a new one in your project.
Step 3: Click on the Python version displayed in the bottom-left corner of the status bar.
If you don’t see any Python version, make sure that the Python extension is installed.
A dropdown list will appear with the available Python interpreters.
The current active interpreter has a checkmark next to it, and the version number is displayed on the right side.
How to check Python version in PyCharm
PyCharm is another widely used IDE for Python development. To check the Python version in PyCharm, follow these steps:
Step 1: Open PyCharm.
Step 2: Go to the main toolbar and click on “File” > “Settings” (or “Preferences” on macOS).
Step 3: On the left-side panel, select “Project: Your_Project_Name” > “Python Interpreter”.
Step 4: On the right-side panel, you will see the Python version installed in your virtual environment listed next to the interpreter executable path.
By following these steps in each respective IDE, you can easily check which version of Python your project is using.
Now that you have knowledge about the Python version you are using, what can you do with this information?
At times, you might receive files from a coworker where the code written is in a newer version of Python, whereas you might be using an older version or vice versa. In such cases, you’ll first need to identify the Python version installed on your system.
What if you’d like to update your Python version to the latest version as you might have different Python versions installed? In the section below, we have listed down a few ways you can use to update your Python version to the latest version.
How to Update a Python Version to The Latest Version
Updating a Python version is as simple as installing Python, however, the procedure for updating varies depending on the operating system you are using.
In this section, we’ll provide an overview of the steps necessary to update Python on Windows, Linus and MacOS.
Updating Python on Windows
Step 1: Uninstall the Python version
Go to Control Panel > Programs and Features.
Find Python in the list of installed programs, click on it, and then click ‘Uninstall.
Step 2: Download and install the latest Python version
-
Visit the Python official download page at https://www.python.org/downloads/.
-
Click on the “Download Python” button
-
Run the installer
-
Follow the installation instructions.
-
Ensure you tick the “Add Python to PATH” checkbox during installation.
After clicking the install button, Python will start being installed on your system
Updating Python on macOS:
Step 1: Install Homebrew (if you haven’t already)
-
Open the Terminal app.
-
Enter the following command, and press Enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Step 2: Update Python
In Terminal, enter the following commands, pressing Enter after each:
brew update
brew upgrade python
Updating Python on Linux (Debian-based distributions):
Step 1: Update package lists
-
Open the Terminal app.
-
Enter the following command, and press Enter:
sudo apt-get update
Step 2: Install the latest Python version
Enter the following command, and press Enter:
sudo apt-get install python3.x
Step 3: Set the default Python version (optional)
Enter the following commands, pressing Enter after each:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.x 1
sudo update-alternatives --config python3
Replace “x” with the latest minor version number, and choose the appropriate version when prompted.
By following these steps, you’ll be able to update Python to the latest version on your Windows, macOS, or Linux system.
Let’s Wrap This Up
Throughout this article, we’ve walked you through a comprehensive guide on how to check which Python version you’re using. We’ve also shown you how to check the Python version directly from a script by utilizing the sys and platform modules.
On top of that, we’ve delved into verifying the Python version in two of the most popular IDEs for Python development: Visual Studio Code and PyCharm.
And, we’ve also laid out the steps you need to follow to update your Python version on Windows, macOS, and Linux systems.
By adhering to these instructions, you can keep your Python environment current, take advantage of the latest features and enhancements, and guarantee the success of your projects.
Looking to learn more about Python, check our Python playlist below:
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:
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
Introduction
Which version of Python do I have installed?
Python is a popular programming language. Like many other programming languages, there can be several different versions organized by release date. Certain applications may require a specific version of Python.
In this tutorial, learn how to check the Python version on Windows, Linux, or macOS systems.
Prerequisites
Access to a command-line/terminal window:
- Linux: Ctrl-Alt-T, Ctrl-Alt-F2
- Windows: Win+R > type powershell > Enter/OK
- MacOS: Finder > Applications > Utilities > Terminal
There are different versions of Python, but the two most popular ones are Python 2.7.x and Python 3.7.x. The x stands for the revision level and could change as new releases come out.
When looking at the version number, there are usually three digits to read:
- the major version
- the minor version
- the micro version
While major releases are not fully compatible, minor releases generally are. Version 3.6.1 should be compatible with 3.7.1 for example. The final digit signifies the latest patches and updates.
Python 2.7 and 3.7 are different applications. Software that’s written in one version often will not work correctly in another version. When using Python, it is essential to know which version an application requires, and which version you have.
Python 2 will stop publishing security updates and patches after 2020. They extended the deadline because of the large number of developers using Python 2.7. Python 3 includes a 2 to 3 utility that helps translate Python 2 code into Python 3.
How to Check Python Version in Linux
Most modern Linux distributions come with Python pre-installed.
To check the version installed, open a terminal window and entering the following:
python --version
How to Check Python Version in Windows
Most out-of-the-box Windows installations do not come with Python pre-installed. However, it is always a good idea to check.
Open Windows Powershell, and enter the following:
python --version
If you have Python installed, it will report the version number.
Alternately, use the Windows Search function to see which version of Python you have:
Press the Windows key to start a search, then type Python. The system will return any results that match. Most likely a match will show something similar to:
Python 3.7 (32-bit)
app
Or,
Python 2.7 (32-bit)
app
This defines which major and minor revision (3.x or 2.x) you are using.
How to Check Python Version in MacOS
If using a MacOS, check the Python version by entering the following command in the terminal:
python -version
The system will report the version.
Note: In some cases, this will return a screen full of information. If that happens, just scan through the file locations for the word python with a number after it. That number is the version.
Checking a System with Multiple Versions of Python
Python2 and Python3 are different programs. Many programs upgrade from the older version to the newer one. However, Python 2.7.x installations can be run separately from the Python 3.7.x version on the same system.
Python 3 is not entirely backward compatible.
To check for Python 2.7.x:
python --version
To check the version of Python 3 software:
python3 --version
Most systems differentiate Python 2 as python and Python 3 as python3. If you do not have Python 2, your system may use the python
command in place of python3
.
Note: Python does not have a built-in upgrade system. You’ll need to download the latest version and install it.
How to Check Python Version in Script
When writing an application, it is helpful to have the software check the version of Python before it runs to prevent crashes and incompatibilities.
Use the following code snippet to check for the correct version of Python:
import sys
if not sys.version_info.major == 3 and sys.version_info.minor >= 6:
print("Python 3.6 or higher is required.")
print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))
sys.exit(1)
When this script runs, it will test to see if Python 3.6 is installed on the system. If not, it will send a notification and displays the current Python version.
Conclusion
You should now have a solid understanding of how to check for the version of Python installed in several different operating systems. Python is a powerful programming language, thus it’s important to understand its different versions.
If you want to learn how to upgrade Python to a newer version on Wondows, macOs, and Linux, check our article how to upgrade Python to 3.9.
I have to run a Python script on a Windows server. How can I know which version of Python I have, and does it even really matter?
I was thinking of updating to the latest version of Python.
asked Jan 18, 2012 at 21:43
6
In a Python IDE, just copy and paste in the following code and run it (the version will come up in the output area):
import sys
print(sys.version)
answered Jan 3, 2014 at 4:47
pzppzp
6,2691 gold badge26 silver badges38 bronze badges
6
Python 2.5+:
python --version
Python 2.4-:
python -c 'import sys; print(sys.version)'
mcandre
23k20 gold badges88 silver badges147 bronze badges
answered Jan 18, 2012 at 21:45
AbbasAbbas
6,7204 gold badges36 silver badges49 bronze badges
5
At a command prompt type:
python -V
Or if you have pyenv:
pyenv versions
answered Jan 18, 2012 at 21:45
Brian WillisBrian Willis
22.9k9 gold badges46 silver badges50 bronze badges
0
Although the question is «which version am I using?», this may not actually be everything you need to know. You may have other versions installed and this can cause problems, particularly when installing additional modules. This is my rough-and-ready approach to finding out what versions are installed:
updatedb # Be in root for this
locate site.py # All installations I've ever seen have this
The output for a single Python installation should look something like this:
/usr/lib64/python2.7/site.py
/usr/lib64/python2.7/site.pyc
/usr/lib64/python2.7/site.pyo
Multiple installations will have output something like this:
/root/Python-2.7.6/Lib/site.py
/root/Python-2.7.6/Lib/site.pyc
/root/Python-2.7.6/Lib/site.pyo
/root/Python-2.7.6/Lib/test/test_site.py
/usr/lib/python2.6/site-packages/site.py
/usr/lib/python2.6/site-packages/site.pyc
/usr/lib/python2.6/site-packages/site.pyo
/usr/lib64/python2.6/site.py
/usr/lib64/python2.6/site.pyc
/usr/lib64/python2.6/site.pyo
/usr/local/lib/python2.7/site.py
/usr/local/lib/python2.7/site.pyc
/usr/local/lib/python2.7/site.pyo
/usr/local/lib/python2.7/test/test_site.py
/usr/local/lib/python2.7/test/test_site.pyc
/usr/local/lib/python2.7/test/test_site.pyo
answered May 31, 2015 at 11:17
user2099484user2099484
4,4272 gold badges21 silver badges9 bronze badges
1
When I open Python (command line)
the first thing it tells me is the version.
answered Jan 18, 2012 at 21:47
poypoy
10.1k9 gold badges49 silver badges74 bronze badges
2
In [1]: import sys
In [2]: sys.version
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
In [3]: sys.version_info
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)
In [4]: sys.version_info >= (2,7)
Out[4]: True
In [5]: sys.version_info >= (3,)
Out[5]: False
answered May 26, 2016 at 13:34
wsdzbmwsdzbm
3,1363 gold badges25 silver badges29 bronze badges
In short:
Type
python
in a command prompt
Simply open the command prompt (Win + R) and type cmd
and in the command prompt then typing python
will give you all necessary information regarding versions:
mar10
14.4k5 gold badges40 silver badges64 bronze badges
answered Dec 15, 2016 at 9:48
2
I have Python 3.7.0 on Windows 10.
This is what worked for me in the command prompt and Git Bash:
To run Python and check the version:
py
To only check which version you have:
py --version
or
py -V # Make sure it is a capital V
Note: python
, python --version
, python -V
,Python
, Python --version
, Python -V
did not work for me.
answered Dec 23, 2018 at 3:24
dahianadahiana
1,1812 gold badges9 silver badges11 bronze badges
1
>>> import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))
3.5
so from the command line:
python -c "import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))"
answered Jul 22, 2016 at 7:28
BaczekBaczek
1,1891 gold badge13 silver badges23 bronze badges
Use
python -V
or
python --version
NOTE: Please note that the «V» in the python -V
command is capital V. python -v
(small «v») will launch Python in verbose mode.
answered Nov 21, 2015 at 0:47
Yogesh YadavYogesh Yadav
4,5676 gold badges34 silver badges41 bronze badges
0
You can get the version of Python by using the following command
python --version
You can even get the version of any package installed in venv using pip freeze
as:
pip freeze | grep "package name"
Or using the Python interpreter as:
In [1]: import django
In [2]: django.VERSION
Out[2]: (1, 6, 1, 'final', 0)
answered May 17, 2015 at 6:13
PoojaPooja
1,25414 silver badges17 bronze badges
To check the Python version in a Jupyter notebook, you can use:
from platform import python_version
print(python_version())
to get version number, as:
3.7.3
or:
import sys
print(sys.version)
to get more information, as
3.7.3 (default, Apr 24 2019, 13:20:13) [MSC v.1915 32 bit (Intel)]
or:
sys.version_info
to get major, minor and micro versions, as
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
answered Jan 9, 2020 at 19:25
nucsit026nucsit026
6527 silver badges16 bronze badges
On Windows 10 with Python 3.9.1, using the command line:
py -V
Python 3.9.1
py --version
Python 3.9.1
py -VV
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit
(AMD64)]
answered Sep 12, 2016 at 15:04
SamSam
2233 silver badges7 bronze badges
2
If you are already in a REPL window and don’t see the welcome message with the version number, you can use help() to see the major and minor version:
>>>help()
Welcome to Python 3.6's help utility!
...
answered Feb 15, 2019 at 12:41
OrigamiEyeOrigamiEye
8741 gold badge12 silver badges31 bronze badges
Typing where python
on Windows into a Command Prompt may tell you where multiple different versions of python are installed, assuming they have been added to your path.
Typing python -V
into the Command Prompt should display the version.
answered Feb 8, 2020 at 5:07
Pro QPro Q
4,4444 gold badges44 silver badges94 bronze badges
If you have Python installed then the easiest way you can check the version number is by typing «python» in your command prompt. It will show you the version number and if it is running on 32 bit or 64 bit and some other information. For some applications you would want to have a latest version and sometimes not. It depends on what packages you want to install or use.
answered Aug 13, 2017 at 22:45
1
To verify the Python version for commands on Windows, run the following commands in a command prompt and verify the output:
c:\> python -V
Python 2.7.16
c:\> py -2 -V
Python 2.7.16
c:\> py -3 -V
Python 3.7.3
Also, to see the folder configuration for each Python version, run the following commands:
For Python 2, 'py -2 -m site'
For Python 3, 'py -3 -m site'
answered Apr 2, 2019 at 17:16
The default Python version and the paths of all installed versions on Windows:
py -0p
One-Liners:
❯❯ python -V | cut -c8-
3.11.0
❯❯ ~ python -VV
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ python --version
Python 3.11.0
❯❯ ~ py --list
-V:3.11 * Python 3.11 (64-bit)
-V:3.10 Python 3.10 (64-bit)
-V:3.9 Python 3.9 (64-bit)
❯❯ ~ py -V
Python 3.11.0
❯❯ ~ py -VV
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ py --version
Python 3.11.0
❯❯ ~ py -0p
-V:3.11 * W:\Windows 10\Python311\python.exe
-V:3.10 W:\Windows 10\Python310\python.exe
-V:3.9 C:\Program Files\Python39\python.exe
❯❯ ~ python -c 'import sys; print(".".join(sys.version.split(".")[0:2]))'
3.11
❯❯ ~ python -c 'import sys; print(sys.version)'
3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ python -c 'import sys; print((str(sys.version_info.major) +"."+ str(sys.version_info.minor)))'
3.11
❯❯ ~ python -c 'import sys; print(sys.version_info)' sys.version_info(major=3, minor=11, micro=0, releaselevel='final', serial=0)
❯❯ ~ python -c 'import platform; print(platform.python_version()[:-2])'
3.11
❯❯ ~ python -c 'import platform; print(platform.python_version())'
3.11.0
❯❯ ~ python -c 'import platform; print("{0[0]}.{0[1]}".format(platform.python_version_tuple()))'
3.11
❯❯ ~ python -c 'import platform; print(platform.python_version_tuple())'
('3', '11', '0')
answered Dec 5, 2021 at 11:44
SzczerskiSzczerski
85811 silver badges12 bronze badges
For me, opening CMD and running
py
will show something like
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
answered Dec 29, 2015 at 12:42
1
Just create a file ending with .py and paste the code below into and run it.
#!/usr/bin/python3.6
import platform
import sys
def linux_dist():
try:
return platform.linux_distribution()
except:
return "N/A"
print("""Python version: %s
dist: %s
linux_distribution: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
""" % (
sys.version.split('\n'),
str(platform.dist()),
linux_dist(),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version(),
))
If several Python interpreter versions are installed on a system, run the following commands.
On Linux, run in a terminal:
ll /usr/bin/python*
On Windows, run in a command prompt:
dir %LOCALAPPDATA%\Programs\Python
answered Mar 19, 2018 at 13:24
Don MatteoDon Matteo
851 silver badge8 bronze badges
1
There are two simple ways to check for the version of Python installed.
Run any of the codes on the command prompt:
python -v
or
python --version
answered Jul 28, 2022 at 4:43
Happy N. MondayHappy N. Monday
3811 gold badge3 silver badges8 bronze badges
For the latest versions please use the below command for the python version
py -V
answered Aug 1, 2022 at 3:56
Jb-99Jb-99
1631 silver badge10 bronze badges
Mostly usage commands:
python -version
Or
python -V
answered Jun 8, 2020 at 12:23
KittoMiKittoMi
4115 silver badges19 bronze badges
For bash scripts this would be the easiest way:
# In the form major.minor.micro e.g. '3.6.8'
# The second part excludes the 'Python ' prefix
PYTHON_VERSION=`python3 --version | awk '{print $2}'`
echo "python3 version: ${PYTHON_VERSION}"
python3 version: 3.6.8
And if you just need the major.minor
version (e.g. 3.6
) you can either use the above and then pick the first 3 characters:
PYTHON_VERSION=`python3 --version | awk '{print $2}'`
echo "python3 major.minor: ${PYTHON_VERSION:0:3}"
python3 major.minor: 3.6
or
PYTHON_VERSION=`python3 -c 'import sys; print(str(sys.version_info[0])+"."+str(sys.version_info[1]))'`
echo "python3 major.minor: ${PYTHON_VERSION}"
python3 major.minor: 3.6
answered Jan 8, 2021 at 12:31
Open a command prompt window (press Windows + R, type in cmd
, and hit Enter).
Type python.exe
answered Jun 29, 2017 at 7:28
ErinaErina
811 gold badge2 silver badges13 bronze badges
1
Before learning how to check the python version, we should first understand Python and its versions briefly.
Python is an object-oriented, high-level interpreted scripting language.
Let us discuss some of the various important points regarding the Python programming language :
- Python programming language is a highly readable language making it easy to understand for new coders.
- ABC programming language can be considered the predecessor of the Python programming language. Modula-3 also has some influence on the Python programming language.
- The Python programming language was developed by Guido Van Rossum in the Netherlands in 1991.
- Python language is widely used in various technical fields such as Artificial Intelligence (AI), Machine Learning (ML), Scientific Calculation, Desktop Application, Web Development (using Django, and Flask framework, etc.) Mobile Application Development, etc.
Let us learn how to check the python version using the command line and scripts.
Check Python Version: Command-Line
Let us first learn how to check the python version using the various command-line commands used in different operating systems.
i) Windows:
In Windows operating systems, we can use the command python —version to check the python version.
The steps to check the python version in Windows are very simple:
- Open the Windows command prompt or Windows Powershell, and enter the following command on the shell :
If we have a Python interpreter installed on the Windows operating system then the command will show the version like :
Output :
Note :
- The version number may differ, but if the Python interpreter is installed in a system, it will similarly show the version.
- We can also search for Python present on the system. We can press the Windows key to launch the search menu and then we can type Python. If the system has installed Python, it will show the Python version.|
ii) MacOS :
In macOS operating systems, we can use the same command, python —version, to check the python version.
The steps to check the python version in macOS are very simple:
- Open the macOS Terminal, and enter the following command on the shell or terminal :
If we have a Python interpreter installed on the macOS operating system, then the command will show the version like :
Output :
iii) Linux :
In Linux operating systems, we can use the same command, python —version to check the python version.
The steps to check the python version in Linux are very simple:
- Open the Linux terminal or shell and type the following command :
If we have a Python interpreter installed on the Linux operating system, then the command will show the version like :
Output :
Note:
We can use the commands such as python —version or python -v or python -VV. All of these commands will provide a similar result. The -VV option is a new command added since Python 3.6. Which can be used for detailed information than -V or —version.
Check Python Version: Script
Let us now learn how to check the python version using scripts.
We can use the sys module or the platform module of the standard library to check the python version in various operating systems. The script will be the same for all operating systems such as Windows, Mac, Linux, etc.
The script is very useful for checking the python version even tho we have various versions of Python installed on our system. Let us see the script and its related information.
i) Various information string: sys.version :
We can use the .version method in the sys (system) module to print the version of the Python interpreter installed on the system. The sys. version method returns a string that contains the version number of the Python interpreter installed in the system. It also returns additional information about the build number and the compiler used.
let us now look at the script :
Output :
ii) Tuple of version numbers: sys.version_info :
We can also use the .version_info method in the sys (system) module to print the version of the Python interpreter installed on the system. The sys.version_info method returns a tuple containing five components of the Python interpreter version number: the major version release number, the minor version release number, the micro version release number, the release level, and the serial number.
let us now look at the script :
Output :
Note :
The release level element is a string, and the other output elements are integers.
iii) Version number string: platform.python_version() :
We can also use the .python_version() method present in the platform module to print the version of the Python interpreter installed on the system. The platform.python_version() method returns a string in the form major.minor.patchlevel. The string denotes the major release number then the minor release number, and then the patch level, each separated using a dot(.)
let us now look at the script:
Output :
The script is handy when we want to check the Python interpreter version number as a simple string only.
iv) Tuple of version number strings: platform.python_version_tuple() :
We can also use the .python_version_tuple() method present in the platform module to print the version of the Python interpreter installed on the system. The platform.python_version_tuple() method returns a tuple in the form ‘major’, ‘minor’, ‘patchlevel’. The tuple denotes the major release number, then the minor release number, and then the patch level, each separated using a comma(,). Each element of the tuple is in the form of a string.
let us now look at the script:
Output :
What are the Different Python Versions?
We have already discussed what Python programming language is and how to check the python version, let us briefly discuss the various popular versions of the Python programming language.
- The first version of Python was released in 1994 named Python 1.0. Python 1.0 had various features like lambda function, map, filter, reduce, etc.
- The second version of Python was released in 2000, with many major new features such as garbage collection systems, list comprehensions, etc.
- The third and latest major Python version release was released in 2008. This version of Python (Python 3.0) is also known as Py3K.
Refer to the below-specified table to check the various Python interpreter versions and their release dates.
Python Versions | Release Date |
---|---|
Python 1.0 | January 1994 |
Python 1.5 | December 31, 1997 |
Python 1.6 | September 5, 2000 |
Python 2.0 | October 16, 2000 |
Python 2.1 | April 17, 2001 |
Python 2.2 | December 21, 2001 |
Python 2.3 | July 29, 2003 |
Python 2.4 | November 30, 2004 |
Python 2.5 | September 19, 2006 |
Python 2.6 | October 1, 2008 |
Python 2.7 | July 3, 2010 |
Python 3.0 | December 3, 2008 |
Python 3.1 | June 27, 2009 |
Python 3.2 | February 20, 2011 |
Python 3.3 | September 29, 2012 |
Python 3.4 | March 16, 2014 |
Python 3.5 | September 13, 2015 |
Python 3.6 | December 23, 2016 |
Python 3.7 | June 27, 2018 |
Python 3.8 | October 14, 2019 |
How to Upgrade to a Newer Version?
We can easily upgrade to the latest or newer version of the Python interpreter by simply going to the (visiting) Python downloads page and downloading the latest version.
What if Your Computer has Multiple Python Versions Installed?
We can have multiple Python interpreter versions installed on our system. We can run a particular python program (or python script) using the specified Python interpreter version.
For example, if we have Python 2.6 and Python 3.6 installed on our system, then we can run a file (let’s say program.py) using both interpreters.
Example : (For Python 3.6)
Example : (For Python 2.6)
Ready to take your Python skills to new heights? Enroll in our free Python course with certificate and become a certified Python pro! Click here to start your journey.
Python 2 vs Python 3
Both Python 2 and Python 3 are very popular interpreters, let us discuss some of the major differences between both releases.
Python 2 | Python 3 |
---|---|
Python 2 was released in 2000. | Python 3 was released in 2008. |
Python 2 interpreter considers print as a statement but not a function. | Python 3 interpreter considers print() as a function. |
The strings are by default stored as UNICODE characters in Python 2. | The strings are by default stored as ASCII characters in Python 2. |
The division of two integral values in Python 2 results in another integral value. For example, 7/2 yields 3. | The division of two integral values in Python 3 results in a floating-point value. For example, 7/2 yields 3.5 |
Exception in Python 2 was dealt with in the enclosed notations. | Exceptions in Python 3 are enclosed in parentheses. |
We used the xrange() function for iteration in Python 2. | We use the range() function for iteration in Python 3. |
Python 2 is not longer in use since the year 2020. | Python 3 is more popular than Python 3 but in some places, we still use Python 2. |
With some effort, we can port the Python 2 code to Python 3. | Python 3 has no backward compatibility with the previous version i.e. Python 2.} |
Learn More
To learn more about the Python Programming Language, refer to the articles :
- Install Python on Windows
- How to Install Python on Linux?
- How to Install Python on macOS?
Conclusion
- In Windows operating systems, we can use the command python —version to check the python version. We just need to open the Windows command prompt, or Windows Powershell, and enter the command.
- In macOS operating systems and Linux operating systems, we can use the same command python —version to check the python version.
- We can use the sys. version method present in the sys (system) module to print the version of the Python interpreter installed on the system.
- The sys. version method returns a string that contains the version number of the Python interpreter installed in the system.
- The sys.version_info method returns a tuple that contains a major version number, the minor number, the micro version number, the release level, and the serial number.
- The platform.python_version() method returns a string in the form major.minor.patchlevel.
- We can also use the .python_version_tuple(). The platform.python_version_tuple() method returns a tuple in the form ‘major’, ‘minor’, ‘patchlevel’.
- The tuple denotes the major release number, the minor release number, and then the patch level separated using a comma(,). Each element of the tuple is in the form of a string.
- We can have multiple Python interpreter versions installed on our system. We can run a particular python program (or python script) using the specified Python interpreter version.