What’s New ?

The Top 10 favtutor Features You Might Have Overlooked

Read More

How to Check Python Version (on Windows or using code)

  • May 01, 2023
  • 5 Minute Read
  • Why Trust Us
    We uphold a strict editorial policy that emphasizes factual accuracy, relevance, and impartiality. Our content is crafted by top technical writers with deep knowledge in the fields of computer science and data science, ensuring each piece is meticulously reviewed by a team of seasoned editors to guarantee compliance with the highest standards in educational content creation and publishing.
  • By Komal Gupta
How to Check Python Version (on Windows or using code)

Finding the version of Python you are using is important to ensure that your code is secure, and is compatible with the packages. In this article, we will look at numerous ways to check the Python version on various operating systems.

How to get Python Version?

On your computer, Python can be installed in many versions. Every developer should know how to check the Python version because it allows them to make sure they are using the right version of the language for their projects. Developers also prefer to use virtual environments to set up various versions together for various projects.

You can use the built-in 'sys.version' method to check the version of Python that is currently being used. The built date and time as well as the version number are returned by this function.

Check this example:

import sys
print(sys.version)

 

Output:

3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]

 

The 'sys.version' is a part of the built-in sys module that can be used to access variables maintained by the Python interpreter. When you import the sys module, you can access various system-specific parameters and functions. You can check the current releases of Python for a better understanding.

One of the most important reasons to know the Python version you have is Compatibility. The code you have may not work because some newer versions might change the syntax. Also, security is an important aspect to ensure that vulnerabilities are fixed, especially when the project is internet-based.  Also, the newer versions have performance improvements and bug fixes.

Check the Python version on Windows/Terminal /MAC/Linux

If you are on your computer, there is an easier way to get the Python version. Use the Command Prompt or Terminal on your Windows or MAC operating systems. It will also work on Linux OS as well. Just type the following command and you will get the answer:

python --version

 

Output:

Python 3.10.11

 

You can enter this command in any terminal, including the VS code terminal or the Windows command prompt.  But if you have multiple versions of Python installed on your system, you can specify the version number to get the exact detail. You can check the version of Python 3 by typing 'python3 --version' command prompt.

How to Check the Python Version Using Python Code?

You can check the version of Python installed on your system using Python code by using platform.python_version(). This function is part of the built-in platform module that returns the Python interpreter's version as a string. 

Here is the Syntax:

import platform
print(platform.python_version())

 

Output:

3.10.11

 

This is different because it only returns the version number, while 'sys.version' returns additional details such as the build date and compiler information as well.

Conclusion

Here we learned how to check the version of Python on your system easily. You can also look at these Python Projects for Beginners to test your skills better. Happy Learning :)

FavTutor - 24x7 Live Coding Help from Expert Tutors!

About The Author
Komal Gupta
I am a driven and ambitious individual who is passionate about programming and technology. I have experience in Java, Python, and machine learning, and I am constantly seeking to improve and expand my knowledge in these areas. I am an AI/ML researcher. I enjoy sharing my technical knowledge as a content writer to help the community.