Sometimes you might require to check the current version that is being run by your Python Scripts. This article is a quick guide to checking the python version that your scripts are executed on. I’ve demonstrated two version checks, one is the human-readable version and the other is the hexadecimal version.
Getting a Human-Readable (Simple Numeric) Version of Python
All you need to find out the simple numerical version of python installed on your system is to run the python command with capital V as an option. The exact command is written below.
Simply run this command in the command prompt or any of the other python execution terminal windows and you’ll find the numerical human-readable current running python version printed on your screen. The screenshot for the demonstration of the same is given below.
Detailed Version Details (Additional Information & Hexadecimal Version)
To get some insights about the current running python version on your machine, you can use the
sys module which comes pre-installed with Python. All you need to do is first import the sys module and use the different properties such as
sys.hexversion to get details of the version as per your requirement.
Run the following commands to get further version details.
import sys sys.version_info
I’ve executed all of these commands in the command prompt after entering into the python command line by simply typing
python first into the command line and then the command as specified above.
You can clearly see in the screenshot the different properties of
sys give different and more specific version details.
Note. There may be several other ways to find out the installed python version on your system as well. You can share any other way to find out the Python version in the comments section if you know one.
One more way we found is using the python_version() function included in the platform python module from stdlib.
from platform import python_version print(python_version())
The following screenshot is the command-line execution representation for the same.
I hope as a beginner, you found this article useful. If so, do share it with others who might get benefit from this article as well. Feel free to ask any kind of questions related to this article in the comments section.