Python Basics5
Python Basics5
[MSC v.1933 64
(AMD64)]’
Table of Content:
The following code can be used for the sys module as shown below:
import sys
sys. version
Output:
To execute the above script, invoke python first in the command line to get the
above results.
The following code can be used for the sys module as shown below:
import platform
print(platform.python_version())
Output:
3.10.7
Python code:
https://www.guru99.com/check-python-version.html 3/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Output:
To get the information on the version of python, use the following script as shown
below:
Python command:
print(sys.version_info)
Output
Sys.version_info(major=3,
minor=10,micro=7,releaselevel=’final’,serial=0)
Screenshot
https://www.guru99.com/check-python-version.html 4/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
To get the tuple information on the version of python, use the following script as
shown below: –
Python command
print(type(sys.version_info))
Output
<class ‘sys.version_info’>
Screenshot
To get the major information on the version of python, use the following script as
shown below: –
Python command
print(sys.version_info[0])
Output
https://www.guru99.com/check-python-version.html 5/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
RELATED ARTICLES
→ Python DateTime, TimeDelta, Strftime(Format) with Examples
→ How to Read CSV File in Python (Module, Pandas Examples)
→ Enumerate() Function in Python: Loop, Tuple, String (Example)
→ Python List Append() with Examples
Screenshot
Python command
print(sys.version_info.major)
Output
Screenshot
https://www.guru99.com/check-python-version.html 6/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
To get the information on the platform python, use the following script as shown
below: –
Python command
Import platform
print(platform.python_version())
Output
3.10.7
Screenshot
To get the type information on the platform version of python, use the following
script as shown below: –
Python command
print(type(platform.python_version()))
Output
<class ‘str’>
Screenshot
https://www.guru99.com/check-python-version.html 7/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
To get the tuple information on the version of python, use the following script as
shown below: –
Python command
print(platform.python_version_tuple())
Output
(‘3’,’7’,’0’)
Screenshot
Python command
print(type(platform.python_version_tuple())
Output
<class ‘tuple’>
https://www.guru99.com/check-python-version.html 8/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Screenshot
Command code:
python3 --version
Output:
Python 3.10.7
Note: Before running the command, ensure that Python is pre-installed on the
computer.
Command code:
python --version
https://www.guru99.com/check-python-version.html 9/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Output:
Python 3.10.7
Refer to the below screenshot for the results executed in the command prompt:
Screenshot:
Open the power shell prompt by typing PowerShell in the start menu and
clicking on Windows PowerShell.
The user must type the following command in PowerShell to obtain the
Python version name.
PowerShell code:
python3 --version
Output:
Python 3.10.7
PowerShell code:
python --version
Output:
Python 3.10.7
See this screenshot for the results executed in the command prompt:
https://www.guru99.com/check-python-version.html 11/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Step 3) Type the below command in the Terminal of Linux to get the version
name of Python.
python3 --version
Output:
Python 3.5.2
python --version
https://www.guru99.com/check-python-version.html 12/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Output:
Python 2.7.12
The above command helps the user check whether python 2 is installed in the
system. Refer to the below screenshot for the results executed in the Linux
terminal:
Screenshot:
Alternatively, the following commands can be used in the Linux terminal to get
the version name of the Python installed in the distribution as listed below: –
python -VV
Output
Python 2.7.12
Screenshot: –
https://www.guru99.com/check-python-version.html 13/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Output
Screenshot:
Output
sys.version_info(major=3,minor=2,releaselevel=’final’,serial=0)
Screenshot:
https://www.guru99.com/check-python-version.html 14/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Output
3.5.2
Screenshot:
The only difference in the above commands is the use of python modules. This
module provides names for variables and functions that are used to
manipulate different parts of the Python environment. The module gets
underlying platform data such as operating system, hardware, and interpreter.
https://www.guru99.com/check-python-version.html 15/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Step 3) To obtain the Python version name, you need to use the following
command in the Terminal window.
Note: However, before running the command, ensure that Python is pre-
installed on the computer. Most advanced versions of Mac OS distributions
have Python pre-installed in it.
python3 --version
Output:
Python 3.3.1
python --version
https://www.guru99.com/check-python-version.html 16/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Output:
Python 2.7.4
The above command helps the user check whether python 2 is installed in the
system.
Refer to the below screenshot for the results executed in the Mac OS terminal:
Screenshot:
To validate both versions, the user can open the command line and type in the
following commands:
python --version
OS Command:
python3 --version
Python 2 or Python 3
Here are comparisons of both versions:
Conclusion
Python version 2 and python version 3 have different syntax
The Python version can be checked in several ways as
Using Windows PowerShell
In the Windows command line.
Terminal of Mac OS and Linux
Using Python scripts.
The version of Python can be checked by typing Python –version
command.
To validate the installation of the Python 3 version, type the command
python 3 –version in the respective OS command lines.
https://www.guru99.com/check-python-version.html 18/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
FAQ:
❓ How do open command lines in different Operating systems?
Python map()
map()
function with
EXAMPLES
EXAMPLES
About
About Us
Advertise with Us
Contact Us
https://www.guru99.com/check-python-version.html 19/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows
Career Suggestion
SAP Career Suggestion Tool
Software Testing as a Career
Xero
RemotePC
QuickBooks
Interesting
eBook
Blog
Quiz
SAP eBook
Privacy Manager
https://www.guru99.com/check-python-version.html 20/20