Python Version

How to Check Your Python Version?

Simple Answer: To check your Python version, run python --version in your command line or shell.

This general method works across all major operating systems (Windows, Linux, and macOS).


Do you need to google important Python keywords again and again? Simply download this popular Python cheat sheet, print the high-resolution PDF, and pin it to your office wall: 🐍


In the following video, I’ll show you how to check your Python version for each operating system (Windows, macOS, Linux, Ubuntu) and programming framework (Jupyter). Or scroll down to read the step-by-step instructions on how to check your Python version.

The Python version output consists of three numbers major:minor:micro. For example, version 3.7.2 means that

  • the major version is 3,
  • the minor version is 7, and
  • the micro version is 2.

[ATTENTION] Different major versions are NOT fully compatible. Different minor versions are compatible.

For example, you can execute code written in Python 3.6.4 in Python 3.7.2 because they are the same major version — Python 3. But you cannot execute code written in Python 2.7.4 in Python 3.7.2 because they are different major versions.

Note that new minor versions can add changes to the language. For example, in Python 3.8 they introduced the reversed() function with dictionaries. This cannot be used in older versions of Python. But the vast majority of the language is the same.

Check Python Version Windows 10 (Exact Steps)

Three steps to check the Python version on your Win 10 operating system:

  1. Open the Powershell application: Press the windows key to open the start screen. In the search box, type “powershell”. Press enter.
  2. Execute command: type python --version and press enter.
  3. The Python version appears in the next line below your command.

Check Python Version Windows 7 (Exact Steps)

Three steps to check the Python version on your Win 7 operating system.

  1. Open the command prompt application: Press the windows key to open the start screen. In the search box type “command”. Click on the command prompt application.
  2. Execute command: type python --version and press enter.
  3. The Python version appears in the next line right below your command.

Check Python Version Mac (Exact Steps)

Four steps to check the Python version on your Mac operating system.

  1. Press CMD + Space to open Spotlight.
  2. Type “terminal” and press enter.
  3. Execute command: type python --version or python -V and press enter.
  4. The Python version appears in the next line below your command.

Check Python Version Linux (Exact Steps)

Three steps to check the Python version on your Linux operating system.

  1. Open the terminal application (e.g. bash).
  2. Execute command: type in python --version or python -V and press enter.
  3. The Python version appears in the next line below your command.

Check Python Version Ubuntu (Exact Steps)

Four steps to check the Python version on your Ubuntu operating system.

  1. Open Dash: click the upper left symbol.
  2. Open terminal: type “terminal”, click on the terminal app.
  3. Execute command: type python --version or python -V and press enter.
  4. The Python version appears in the next line right below your command.

Check Python Version Jupyter (Exact Steps)

Three steps to check the Python version in a Jupyter notebook.

  1. Open the Jupyter notebook: type jupyter notebook in your terminal / console
  2. Write the following Python code snippet in a code cell:

from platform import python_version
print(python_version())

3. Execute the script.

As an alternative, you can also use the following Python code snippet to check your Python version in a Jupyter notebook:

>>> import sys
>>> sys.version

Here is a screenshot on my computer:

How to Check Which Python Version Runs Your Script?

Sometimes, you want to check Python’s version in your Python program.

To achieve this, simply import the sys module and print the sys.version attribute to your Python shell:

>>> import sys
>>> print(sys.version)
3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]

Import the built-in sys module and print sys.version for human-readable output. 

What are the Different Python Versions?

Python has three main versions: version 1, version 2, and version 3. Version 4 is currently (2019) under development.

Here is the version history from Wikipedia.

  • Python 0.9.0 – February 20, 1991
    • Python 0.9.1 – February, 1991
    • Python 0.9.2 – Autumn, 1991
    • Python 0.9.4 – December 24, 1991
    • Python 0.9.5 – January 2, 1992
    • Python 0.9.6 – April 6, 1992
    • Python 0.9.8 – January 9, 1993
    • Python 0.9.9 – July 29, 1993
  • Python 1.0 – January 1994
    • Python 1.2 – April 10, 1995
    • Python 1.3 – October 12, 1995
    • Python 1.4 – October 25, 1996
    • Python 1.5 – December 31, 1997
    • Python 1.6 – September 5, 2000
  • Python 2.0 – October 16, 2000
    • Python 2.1 – April 15, 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

As there are some major differences in syntax, you should always install the latest version in Python. Keep yourself updated on the official Python website here.

How to Upgrade to a Newer Version?

If you are not using a virtual environment, go to python.org/downloads to download and install whatever version you need. There is no simpler way to upgrade Python. 

But now you’ll run into the following problem: how do I run a specific Python version? Check out this StackOverflow answer to learn the exact steps.

Or you can make your life easier by using virtual environments. These let you have multiple versions of Python installed on your system. Plus you can switch between them instantaneously. One option is to use the built-in module venv. If you’re a Data Scientist, the industry standard is Anaconda.

Installing and upgrading different Python versions is easy when you use virtual environments. For a full tutorial of virtual environments, read over our introductory Finxter blog article.

How to Check if Python 3 is Installed?

If you’ve installed multiple installations of Python, running python --version may give you only the version of Python 2 on your computer. To check which version of Python 3 is installed on your computer, simply run the command python3 --version instead of python --version.

How to Check Python Version – Detailed

Not only does Python have major, minor and micro versions. Each of those versions has further versions, namely the release level and serial.

These are displayed when you run

>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=8, micro=0, releaselevel='final', serial=0)

In the above code, I am running Python 3.8.0.

Most of the time, you will only care about the major, minor and micro releases. Release level and serial are usually for the core Python Dev team to work on changes to the language.

The possible release levels are ‘alpha’, ‘beta’, ‘candidate’ or ‘final’. Alpha contains the first updates made to the language. Beta means the language can be tested with some users but still won’t work perfectly. This is where the phrase ‘beta testers’ comes from. A ‘candidate’ has only a few small bugs left to fix. Final is the last version and the one released to the general public. If you want to try out new features before anyone else, you can download these release levels. However, if you just want a version of Python that works, you should choose ‘final’. When you download any version of Python, it will be a ‘final’ release unless stated otherwise.

Serial is for the smallest changes. It is incremented by the Python Dev team as they make changes to the alpha, beta and candidate versions. All final versions have serial=0. They add future changes to the next major/minor/micro releases.

How to Make Sure My Script Runs a Specific Python Version?

Let’s say you’ve just installed Python 3.8 and your script, my_file.py, uses a brand new feature: reversed() when iterating over a dictionary. For other people to run this script, they must also run Python 3.8. So you should put a check at the start to let other users know this.

We do this by adding an assert statement at the top of my_file.py

# my_file.py
import sys
assert sys.version_info >= (3, 8)

my_dict = dict(a=1, b=2, c=3)
for key in reversed(my_dict):
    print(key)

The assert statement raises an AssertionError if the statement is False. If the statement is True, the script continues to run.

For example, if I am running Python 3.7 and execute my_file.py from the terminal, this happens

# Running Python 3.7
$ python my_file.py
Traceback (most recent call last):
  File "my_file.py", line 10, in <module>
    assert sys.version_info >= (3,8)
AssertionError

But if I am running Python 3.8, the assert statement does not raise an error and the rest of the script is executed.

# Running Python 3.8
$ python my_file.py
c
b
a

Note: I have used the Anaconda virtual environment to install and quickly switch between multiple Python versions.

Where to Go From Here?

In summary, you can check the Python version by typing python --version in your operating system shell or command line.


Do you struggle with Python? And Python source code sometimes feels like a closed book to you?

If this applies to you, check out my free email course! The course guides you step-by-step to a deeper and deeper Python level of code understanding. Here is what my readers say:

Thank you for your newsletter. I find these newsletters highly informative.

Collen

As a fellow educator and fellow (former) Ph.D. student, I just wanted to let you know that I’m really impressed with your teaching materials. You’re doing a really good job!

Daniel