How to Check Python Version on Windows, Linux, and MacOs

How to Check Python Version?

Introduction to Python – Programming Language

Picture this: you’ve just started your Python journey, eager to write your first lines of code and unleash your creativity. But as you delve deeper into tutorials and projects, you realize that understanding your Python version is crucial for ensuring compatibility and troubleshooting potential issues. Suddenly, you’re faced with a dilemma: how do you check your Python version amidst the sea of command lines and technical jargon?

Fear not, fellow Python enthusiasts, for help is at hand. In this article, we embark on a quest to demystify Python versioning, offering a guiding light to those navigating the labyrinth of Python’s landscape for the first time. Whether you’re a coding novice taking your first steps into the world of programming or a seasoned learner looking to brush up on your skills, this guide is tailored to empower you with the knowledge and confidence needed to conquer Python’s mysteries.

Join us as we unravel the intricacies of Python versioning, providing clear and concise instructions for identifying your Python version. By the end of this journey, you’ll emerge not only with a newfound understanding of Python’s versioning system but also with the tools and confidence to embark on your Python adventure with clarity and purpose. So, grab your code editor and let’s embark on this exhilarating journey together!

Key Takeaways

  • Checking Python version is essential for developers and Python enthusiasts.
  • It helps ensure compatibility with projects and avoids potential errors related to version discrepancies.
  • There are several methods to check Python version, including command line, interactive shell, IDEs, and code.
  • Windows and macOS users can use specific methods to check Python version.
  • It is easy to determine Python version and proceed with projects confidently using the methods highlighted in this article.

Why is Python an Amazing Programming Language?

The introduction to Python language can help you understand why it is considered special. So, Python is an object-oriented high-level programming language. Guido van Rossum developed it and released it in 1991. It is highly popular for beginners due to its simplicity and readability and clear syntax. Also, new programmers can easily learn its concepts.

Python is preferred in different areas such as web development, mathematics, software creation, scripting, etc. It has the ability to integrate different components and has earned it the nickname “Glue Language.” Python is open-source in nature which means a large community of developers constantly makes its libraries and functionalities better. 

Google, Instagram, Netflix, and Spotify use this popular programming language. It enables fast development and efficient execution. Moreover, Python is portable i.e. it allows code to be transferred across different platforms without errors and this aspect makes it a preferred choice among developers worldwide.

Why Checking Python Version is Important

As a Python developer or enthusiast, checking the version of Python installed on your system is crucial. Here are some reasons why:

  • Compatibility: Different versions of Python have different features and capabilities, so it is essential to ensure that the version you are using is compatible with the libraries and frameworks you intend to use.
  • Bug Fixes and Security Patches: New versions of Python come with bug fixes and security patches that address potential vulnerabilities and improve performance. It is crucial to keep up to date with the latest versions, so you don’t miss out on these vital updates.
  • Support: Python has a vast community of developers who continue to add new features and develop new libraries, usually compatible with newer versions of Python. If you are using an older version, you may not receive support for some libraries and may not benefit from the latest advancements.

By keeping track of the Python version on your system, you can improve your project’s stability, security, and performance while keeping up to date with the latest features and libraries.

Command Line Method

The command line method is one of the quickest and most efficient ways to check the Python version installed on your system. This method is particularly useful for developers who are comfortable with executing commands.

To check the Python version using the command line, follow these simple steps:

  1. Open the command prompt on your system.
  2. Type the following command and press Enter: python –version
  3. The Python version installed on your system will be displayed, such as: Python 3.9.2

With these simple steps, you can easily check the Python version using the command line interface. This method works on both Windows and macOS operating systems.

Python Interactive Shell Method

Python interactive shell is a helpful tool for beginners and those who prefer a graphical user interface. Here is how you can check the Python version using the interactive shell:

  1. Open the Python interactive shell by typing “python” (without quotes) in your command prompt or terminal.
  2. Type the following command: import sys
  3. Next, type: sys.version
  4. The command prompt or terminal will display the version of Python installed on your system.

The output will look something like this:

3.9.1 (tags/v3.9.1:1dddb1086e, Dec 5 2020, 12:22:43) [MSC v.1927 64 bit (AMD64)]

Now that you know how to check Python version using interactive shell, you can easily determine if you need to update or install a specific version for your projects.

Check Python Version in Integrated Development Environments (IDEs)

If you are using an integrated development environment (IDE) for your Python projects, you can easily check the Python version installed on your system within the IDE’s interface. We will explore the steps to find the Python version in popular IDEs such as PyCharm, VS Code, and Jupyter Notebook.

PyCharm

In PyCharm, you can find the Python version by opening a Python file and navigating to Settings > Project: your_project_name > Python Interpreter. Here, you will find the version number displayed next to the Python interpreter.

VS Code

To check the Python version in VS Code, open a Python file and select the Python interpreter in the bottom left corner of the editor. The version number will be displayed next to the interpreter name.

Jupyter Notebook

In Jupyter Notebook, you can find the Python version by opening a new notebook and executing the following code in a cell:

import sys
print(sys.version)

The version number will be printed as the output of the code.

How to Check Python Version in Code

Checking the Python version programmatically is necessary for developers who want to ensure that their code is compatible with the specific version of Python their project requires. Here are a few examples of how to check the Python version using different programming languages and frameworks:

Python

To check the Python version using Python, you can use the following code:

import sys
print("Python version")
print(sys.version)

Java

For Java developers, you can use the following code to check the Python version:

Process p = Runtime.getRuntime().exec("python --version");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String version = in.readLine();
System.out.println(version);

JavaScript

If you want to check the Python version using JavaScript, you can use the following code:

var child_process = require('child_process');
child_process.exec('python --version', function (error, stdout, stderr) {
if(stdout) console.log('Python Version: ' + stdout);
if (error !== null) console.log('exec error: ' + error);
});

These are just a few examples of how to programmatically check the Python version. By using these codes, you can ensure that your project is running on the correct version of Python.

Related: Python VS Miropython

How to Check Python Version in Windows

If you’re a Windows user, it’s crucial to know how to check the Python version on your system to ensure compatibility with your projects. Here’s a step-by-step guide on how to do it:

  1. Open the command prompt by pressing the Windows key + R, typing “cmd”, and hitting enter.
  2. Type “python –version” in the command prompt and press enter.
  3. The Python version installed on your Windows system will be displayed.

It’s that simple! Now you can keep track of the Python version to ensure your projects run smoothly on Windows.

How to Check Python Version in Linux

You can ensure compatibility with your applications and development needs by checking the Python Version In Linux. Different methods are discussed below to verify the version of Python installed on your Linux system using the Linux Terminal.

Using Python Package Managers

If Python Package Managers were used for installation, check its detailed information about the version in Linux as below. 

For Debian-based systems such as Ubuntu (use apt) – 

apt show python3

For Red Hat-based systems such as CentOS, (use yum) –

yum info python3

Python Adaptability

Python’s adaptability is useful for easily updating and checking versions. For updating Python On Linux, you can use the package manager commands to update Python to the latest version:

sudo apt update

sudo apt upgrade

How to Check Python Version in macOS

For macOS users, checking the Python version is a straightforward process. Follow these simple steps to ensure compatibility with your projects:

  1. Open the Terminal application.
  2. Type python --version in the command prompt.
  3. Press the Enter key.

After executing these steps, the installed Python version will be displayed on the screen. It’s important to keep track of the version being used to prevent compatibility issues and ensure optimal performance.

How to Check Python Version in Script

Python script needs to run as expected so it is essential to verify the Python version in use. If your environment has multiple Python installations or Python 2 and Python 3, this becomes more important. Below is a basic script to check the Python version with the ‘sys’ or ‘platform’ module. 

  • Python Sys Module – The sys.version attribute gives you a string with the version number (see below). And, sys.version_info provides a tuple with detailed version information.

import sys
# Print Python version
print("Python version")
print(sys.version)
print("Version info.")
print(sys.version_info)

  • Platform module – The platform.python_version() function returns a concise string with the version number (formatted as major.minor.micro).

import platform
# Print Python version
print(“Python version”)
print(platform.python_version())

This script works on different OS including Windows, Mac, and Linux (like Ubuntu).

Conclusion

As we have seen, checking the Python version is crucial for developers and Python enthusiasts. Whether you are a beginner or an experienced programmer, it is essential to keep track of the Python version you are using to ensure compatibility with your projects.

In this article, we have discussed different methods of checking the Python version, including the command line interface, interactive shell, integrated development environments (IDEs), and programmatically using code. By taking a few simple steps, you can easily determine the Python version installed on your system and proceed with your projects confidently.

Remember to always check the Python version before starting a new project or working on an existing one to avoid compatibility issues. With the help of the methods discussed in this article, you can quickly and easily check your Python version and ensure that your projects run smoothly.

So, keep checking your Python version regularly and happy coding!

Related: Python VS Miropython

FAQ on Python Version

How do I check the Python version?

There are several methods to check the Python version. You can use the command line, the Python interactive shell, integrated development environments (IDEs), or even check the version programmatically within your code.

Why is it important to check the Python version?

Checking the Python version is important for developers and Python enthusiasts to ensure compatibility with their projects. Different Python versions may have different functionalities and features, and knowing the version you are using helps in avoiding compatibility issues.

How can I check the Python version using the command line?

To check the Python version using the command line, you need to open the command prompt or terminal and execute the command “python –version” or “python3 –version”. This will display the version number installed on your system.

How do I check the Python version using the interactive shell?

Checking the Python version using the interactive shell is simple. Open the Python interactive shell by executing the command “python” or “python3” in the command prompt or terminal. Then, enter the command “import sys” and “sys.version”. The version number will be displayed.

Can I check the Python version in integrated development environments (IDEs)?

Yes, you can check the Python version within popular IDEs such as PyCharm, VS Code, and Jupyter Notebook. The process may vary slightly depending on the IDE, but typically, you can find the Python version in the settings or preferences section of the IDE.

How can I check the Python version programmatically in my code?

To check the Python version programmatically, you can use different programming languages and frameworks. For example, in Python, you can use the “sys” module and access the “sys.version” attribute. Other languages may have their own methods to retrieve the Python version.

How do I check the Python version on Windows?

If you are using Windows, you can check the Python version by opening the command prompt and executing the command “python –version” or “python3 –version”. The version will be displayed in the command prompt.

How to check Python version in cmd?

To check the Python version in the cmd, you need to follow the below instructions: 

For Windows – Open the Command Prompt and type python –version or python -V, then press Enter. 

For macOS – Open the Terminal and type python –version or python -V, then press Enter. 

For Linux – Open the Terminal and type python –version or python -V, then press Enter. 

If you have multiple version installed, you need to specify the version, for example, python3 –version or python3 -V

How do I check which version of Python is installed on my Windows?

You can check the Python version in Windows easily using the below step:

  • Open Python Command Line Prompt.
  • Run python --version or python -V`

How can I check the Python version on macOS?

On macOS, you can check the Python version by opening the terminal and executing the command “python –version” or “python3 –version”. The version will be displayed in the terminal.

How can I check the version Python 3 installed on my computer?

You can check the Python version on your computer by running the below through the Command Prompt or terminal –

python3 --version

or

python3 -V

How do I check all the versions of Python installed?

You can easily check the version of each installed Python executable using python –version, python2 –version, python3 –version, etc. Also, if you want to list all installed Python versions on Windows, use py -0.

Further, check common installation directories like C:\PythonXX on Windows or /usr/local/bin/ on Unix-based systems.

Alternatively, use the below command to locate Python binaries – 

where python 

OR on Unix-based systems 

which -a python

Further, you can search for Python installations in common directories with –

sudo find / -name 'python*' -type f -executable 2>/dev/null (this command will search the entire filesystem for Python executables).

How do I check Python Version using a Python Script?

You can use any of the below methods in your script –

import sys

print(sys.version)

OR

import platform

print(platform.python_version())

How to check SciPy version?

You need to run the following in Python Shell or script to check SciPy version –

import scipy

print(scipy.__version__)

check python version

check python version in cmd

How to Check Python Version

how to check python version in cmd

how to check python version in linux

how to check python version in mac

python version check

About the Author
Posted by Kavya Desai

Experienced web developer skilled in HTML, CSS, JavaScript, PHP, WordPress, and Drupal. Passionate about creating responsive solutions and growing businesses with new technologies. I also blog, mentor, and follow tech trends. Off-screen, I love hiking and reading about tech innovations.