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:
If you want to find the path to the executable, run the following command:
If you are in Windows, use the following:
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())
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
That’s it. I hope this guide helps you.