How to Check Python Version


1. List Installed Versions

Currently, there are Python 2 and Python 3 versions and they can be installed on one operating system.  If we want to check which versions have been installed, just run this command in Linux OS:

$ ls /usr/bin/python*

You may see output like this. This indicates that both python 2.7 and python 3 have been installed.

/usr/bin/python /usr/bin/python2.7 /usr/bin/python3 

2. Check Version Details

If we want to check more details of versions, we can use these 3 methods:

  • Using Command Line

This method is very easy. It is also often used for checking the version of other programming languages.

$ /usr/bin/python3 -V
OR
/usr/bin/python3 --version
Python 3.6.5
  • Using Python Interpreter

We can also perform Python version check with related function in the Python environment. Here is an example:

$ python
Python 3.6.5 (default, Oct  23 2018, 15:26:19) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.python_version()
'3.6.5'
>>>
  • Using Python Codes

You can print out the Python version by running python codes:

import platform
python_version=platform.python_version()
print (python_version)

3. Check on Windows

The examples above are based on the Linux OS. For Windows, please first launch the Command Prompt by pressing the Win + R keys on your keyboard. Then, type cmd or cmd.exe and press Enter or click/tap OK. When the window is launched, just paste the commands above and modify the Python interpreter address based on the directory Python was installed.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments