4Geeks chosen to deliver AI education in the Bahamas alongside Harvard, Oxford, and Columbia.See more

How to check python version?

Get the latest version of Python with this easy guide! Learn how to check your current version and upgrade to the newest version with just a few clicks. #Python #VersionCheck #Upgrade
4 min readLast updated
cmd
python --version
#Output:  Python 3.11.0

Checking the python version

Short answer: open a terminal (or CMD on Windows) and run python --version or python -V; on macOS and Linux you may need python3 --version. Inside a script, import sys and print(sys.version) shows the version that is running your code (Python documentation for sys.version).

If you have installed python on your system, checking the python version is as simple as writing the following code, doesn't matter the Operating System (OS) you are using since python will respond to the same commands on all of them.

For Windows users:

  • Open command terminal (search on the menu bar for cmd or press WIN + R to open the run window and type cmd)
  • Type python -V or python --version

For Linux users:

  • Open a new terminal
  • Type python -V or python --version

For MacOS users:

  • Go to Finder
  • Click on Applications
  • Select Utilities
  • Terminal
  • Type python -V or python --version
cmd
python -V
#Output: Python 3.11.0

Checking the Python Script Version

If you need to check the Python version that you are using for a project (remember we can have different python versions installed at the same time on our System, we call it Python Script Version), you can do it like this:

Using sys module

python
import sys
print (sys.version)
#Output: 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]

Using the platform module

python
import platform
print(platform.python_version())
#Output: 3.10.4

Both options will return the version with a string format. We can obtain this information in the tuple format as well. The return tuple syntax will contain five components: major, minor, micro, release level, and serial:

python
import sys
print (sys.version_info)
# Output: sys.version_info(major=3, minor=10, micro=4, releaselevel='final', serial=0)

Since we are receiving the information in a Tuple format we can access and extract information using an index or by referring to its name.

python
import sys
print(sys.version_info[0])
#Output: 3
print(sys.version_info.releaselevel)
#Output: final

Hope you enjoy the reading and keep on the Geek side!

Checking your Python version with sys.version_info is often the first step before running any project. To keep growing from there, you can learn to code in a structured program built around real projects and mentor support.

Frequently asked questions

Why does python --version say command not found?

Either Python is not installed or its folder is not in your PATH. On macOS and Linux, try python3 --version, since many systems only provide the python3 command. On Windows, try py --version; if nothing works, reinstall Python from python.org, enable the option that adds Python to PATH, and then open a new terminal.

How do I see every Python version installed on my computer?

On Windows, run py --list (or py -0) to see every version the Python launcher has registered. On macOS and Linux, which -a python3 lists each python3 on your PATH, and ls /usr/bin/python* shows versioned commands such as python3.11. If you manage versions with pyenv, pyenv versions lists them and marks the active one.

How do I check which Python version pip is using?

Run pip --version. The output shows the pip version, its installation path and, in parentheses, the Python version it belongs to. To be sure packages go to a specific interpreter, call pip through it, for example python3 -m pip --version or py -3.11 -m pip --version, and install packages with that same prefix.

How can a Python script require a minimum Python version?

Compare sys.version_info with a tuple, because tuples compare element by element. For example, if sys.version_info < (3, 10): sys.exit("Python 3.10 or newer is required") stops the program with a clear message on older interpreters. Keep this check in a small entry file, since newer syntax elsewhere in the same file can fail before the check runs.