How to Find Python Version [Tutorial]

1 min

Here’s how you can find the Python interpreter version in your system.

It’s essential to know the Python version installed in your system. Because your application or development project deployment, dependencies depends on it. Not to mention, minor Python releases frequently happen with feature updates and security fixes. Hence it’s important for you to know which version is currently installed in your server or local setup.

There are many ways you can find it. You can either find it via command or run a program to find it out.

Find Python Version via command

The most straightforward way to find out in Ubuntu, Fedora and other Linux distributions is by running the following command:

python3 --version

If you want to find the path to the executable, run the following command:

which python

If you are in Windows, use the following:

python --version
Python version on Windows
Python version on Windows

Using Python libraries

Sometimes you need to find the Python version inside the program to implement various logic. For example, you might want to execute a piece of code for an older version of Python for some backward compatibility.

So, you can do it using sys or platform library. Here’s a sample code snippet using sys library. You can write this code in any python editor or run it via Python shell.

import sys

print("current version:", sys.version)

And here’s using the platform library:

from platform import python_version

print("current version:", python_version())
finding python version
finding python version

The above two methods are common to all platforms. If you want to get only the major, minor and revision numbers, then use the python_version() function because it’s easier to compare without any parsing, which you might need to do for sys.version.

That’s it. I hope this guide helps you.


Creator and author of Connect with me via Telegram, Twitter, or send us an email.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Oldest Most Voted
Inline Feedbacks
View all comments