0% found this document useful (0 votes)
7 views20 pages

Python Basics5

How to Check Python Version on Linux, Mac & Windows

Uploaded by

Sridhar M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
7 views20 pages

Python Basics5

How to Check Python Version on Linux, Mac & Windows

Uploaded by

Sridhar M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 20

12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows

How to Check Python Version on Linux, Mac &


Windows
By : Logan Young Updated August 12, 2024

How to Check Python Version


Here are check the Python version using a script

Commands Where What Output


python –version Command Windows/Mac/Linux Python 3.10.7
python -v line or
python -vv Terminal

Import sys Script Use as string ‘3.10.7


sys. version (tags/v3.10.7:6c
Sep 5 2022, 14:0
https://www.guru99.com/check-python-version.html 1/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows

[MSC v.1933 64
(AMD64)]’

Import platform Script String of short ‘3.10.7’


Platform.python_version() format

Platform.python_version_tuple() Script Tuple of short (‘3’,’10’,’7’)


format

Table of Content:

How to check the Python version using a script?


Python scripts can identify the version of Python installed on the computer. It
enables you to validate if multiple versions are installed in the system. The script
developed to check the Python version remains the same for windows OS, Mac OS,
and Linux distributions. You can create a script by importing either the platform
module or sys module of python.

The following code can be used for the sys module as shown below:

Command line Code:

import sys
sys. version

Output:

'3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit


(AMD64)]'

Refer to the following command line screenshot:


https://www.guru99.com/check-python-version.html 2/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows

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:

Command line Code:

import platform
print(platform.python_version())

Output:

3.10.7

Refer to the following command line screenshot:

Use the following code in the web-based interpreter as shown below: –

Python code:

from platform import python_version

print("Current Python Version-", python_version())

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:

Current Python Version- 3.8.10

Refer to the following web-based interpreter screenshot:

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

How to check the Python version using Windows Command


Line?
Here are steps to check the Python version using Windows Command Line:

Step 1) Open the command prompt by typing cmd


Step 2) When the command prompt opens, type the following command in the CLI
to get the version name of Python.

Command code:

python3 --version

Output:

Python 3.10.7

Note: Before running the command, ensure that Python is pre-installed on the
computer.

Alternatively, open a command line and type the below command:

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:

How to check the python version using windows


PowerShell?
To check the Python version in Windows PowerShell:

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.

However, before running this command, ensure that Python is pre-installed on


the computer.
https://www.guru99.com/check-python-version.html 10/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows

Following is the command typed in the command line:

PowerShell code:

python3 --version

Output:

Python 3.10.7

Alternatively, open a command line and type the below command:

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

How to check the Python Version in Linux?


Here are steps to check the Python Version in Linux:

Step 1) To check the Python version in Linux, open the Terminal


Step 2) This opens the below window as shown below:

Step 3) Type the below command in the Terminal of Linux to get the version
name of Python.

Following is the command typed in the Terminal:

Linux Terminal code:

python3 --version

Output:

Python 3.5.2

Alternatively, open the Terminal and type the below command:

Linux terminal code:

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:

Ensure that Python is pre-installed on the operating system of the computer.


Most advanced versions of Linux distributions, such as Ubuntu and Fedora,
have Python pre-installed in it.

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: –

Linux terminal code:

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

Linux terminal code:

Python3 -c “import sys; print(sys. version).”

Output

3.5.2(default, Nov 12 2018, 13:43:14)

[GCC 5.4.0 20160609]

Screenshot:

Linux terminal code:

Python3 -c “import sys; print(sys.version_info)”

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

Linux terminal code:

Python3 -c “import platform; print(platform.python_version())”

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.

How to check the Python version on Mac?


Here are steps to check the Python version:

Step 1) To check the Python version in Mac OS


Open the Terminal by typing the terminal command in the search box in the
top right corner of the Mac OS desktop menu and click on it.

Step 2) This opens the below window as shown below:

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.

Following is the command typed in the Terminal:

Mac OS Terminal code:

python3 --version

Output:

Python 3.3.1

Alternatively, open the Terminal and type the below command:

Mac OS terminal code:

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:

How to check Multiple python versions installed in the


same system?
There can be multiple Python versions installed on the computer system.
Therefore, a computer can have both versions 2 and 3 installed.

To validate both versions, the user can open the command line and type in the
following commands:

Scenario 1: To check Python version 2


Command Line \ Terminal code:

python --version

Scenario 2: To check Python version 3


https://www.guru99.com/check-python-version.html 17/20
12/13/24, 11:29 PM How to Check Python Version on Linux, Mac & Windows

OS Command:

python3 --version

Python 2 or Python 3
Here are comparisons of both versions:

Python version 3, compared to Python version 2 is different in terms of


syntax. Here is a complete comparison between the 2 versions.
Python 3 contains a couple of utilities that help translate code written in
Python 2 to Python 3.
Python version 3 has a different syntax from Python version 2 because
Python versions 2 and 3 have different syntaxes.
Python 2 is not releasing any new updates, which makes this version
incompatible with version 3.
Some features of Python 3 were backported to Python 2, and this was
done to support easy migration.
Python 3 stores strings in Unicode format by default. However, to convert
a string to Unicode format in version 2, it must be defined with the
keyword “u”.

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?

🏅 Perquisites for the system before Checking the Version

You Might Like:

Python TUPLE - Top


Top Python PyQt5 Tutorial
Pack, Unpack, Interview
Interview with Examples:
Compare,… Questions and…
and… Design…

Python map()
map()
function with
EXAMPLES
EXAMPLES

Prev Report a Bug Next

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

English © Copyright - Guru99 2024 Privacy Policy |


Affiliate Disclaimer | ToS | Editorial Policy

https://www.guru99.com/check-python-version.html 20/20

You might also like