- How to Check Python Versions
- How to Check Python Version in Linux, Mac, & Windows
- Checking Python Version in Linux
- Checking Python Version in Mac
- Checking Python Version in Windows
- Checking Python Version with A Program
- Conclusion
- How to Check Your Python Version
- Check Python Version: Command Line
- Windows
- macOS
- Linux
- Check Python Version: Script
- Python 2 or Python 3?
- Time to Practice Python!
How to Check Python Versions
In 2019, The Python Software Foundation announced a change in the release calendar, making it so a new version of the language is released every 12 months.
The organization also announced that every Python version would receive bug-fix updates for a year and a half and security updates for three and a half years before bringing the version to its end-of-life at the end of the five years.
Using the latest version of Python is the best way to ensure you get a bug-free and secure experience.
But how do you check the python version?
It’s a lot easier than you think – but you must first ensure that you have Python installed on your computer. If you haven’t installed Python yet, our easy installation guide will help you set it up in minutes.
If Python is installed on your computer, here’s how you can find the version quickly.
How to Check Python Version in Linux, Mac, & Windows
Python ranked fourth in popularity in the Stack Overflow 2020 Developer Survey. The survey was taken by 65,000 developers across the globe, making it a reliable depiction of developer and business preference of programming language use.
Before you can check what version of Python your computer has loaded, you must understand the version scheme of Python. Every Python version has three digits.
The first digit represents the major version, the second the minor version, and the third digit represents the micro version or “revision level.”
You must also note that major versions are typically not fully compatible with each other. In other words, software written with Python version 2.x.x may not run correctly with Python 3.x.x.
However, minor releases are typically compatible with the previous releases. For example, code written in Python 3.1.x will run with Python 3.9.x (which is the current Python version).
Checking Python Version in Linux
Most modern Linux distributions come with Python pre-installed. You don’t have to type in any lines of code to install it yourself – unless you’re using a relatively less popular Linux distro.
Checking the Python version on a Linux machine is simple. The first step is to open up the Terminal. If you’re using a distribution like Ubuntu, you can go to the menu and search for it.
However, the easiest way to open the Terminal is to press Ctrl+Alt+T. Alternatively, you can press the Ctrl, Alt, and F2 keys together.
A terminal window will appear on your screen. You can then enter the following command:
Your machine can have multiple versions of Python installed. If your machine has Python 3 installed, entering either of the following commands in the Terminal will also do the trick:
After entering the command in the Terminal, press the Enter key. The Python version will appear on the next line, like so:
You can run this command on any hardware that’s running a Linux OS – including a Raspberry Pi.
Checking Python Version in Mac
There is no PowerShell or Command Prompt on macOS. However, the operating system has a terminal like Linux and Unix systems do. You will need to access the Terminal to check the Python version on your Mac.
To open the Terminal, open the Finder. Then navigate to Applications, and select Utilities. Find and launch the Terminal from here.
The instructions from here are similar to the instructions for Windows systems. To find the Python version, you have to enter the following command:
If Python 3 is installed on your computer, too, you can find the exact version of Python 3 you’re using by entering the following command:
The details of the Python version will appear on the next line, like so:
Checking Python Version in Windows
If you’re using Windows 10, you can find the Python version using Windows PowerShell. The simplest way of launching PowerShell is to hit the Windows key and type “powershell.” You can then select it from the list of options that appears.
All you have to do next is type the following:
The details will appear on the next line.
Checking Python Version with A Program
It is possible for you to open the Python interpreter on your Terminal and write a few lines of code to determine the Python version.
To run the Python interpreter on your computer:
- On Windows: Launch PowerShell and type “python” into the Terminal.
- On macOS: Navigate to Applications > Utilities > Terminal and type “python.” If you have Python 3 installed, type “python3.”
- On Linux: Open up the Terminal and type “python” or “python3,” depending on what you have installed on the machine.
If you see “>>>” appear on the Terminal, Python is in interactive mode. Next, you must copy-paste the following lines of code into the interpreter:
print(«User Current Version:-«, sys.version)
The details of the Python version installed will appear in the output.
To exit the interpreter, you can either type in “quit()” or “exit(),” both of which are built-in Python functions.
Alternatively, if you’re on Windows, you can press Shift+Ctrl+Z and Enter. On Unix-like systems, pressing Shift+Ctrl+D should stop the interpreter.
Conclusion
Every version of Python – even the newest release – has its own limitations. However, keeping Python updated will improve security and make the experience less error-ridden.
Updating to the newest version also ensures that you can use the latest features, syntax, and library modules Python has to offer.
Now that you know how to find the version of Python installed on your computer, you can learn if you’re up to date in instants.
How to Check Your Python Version
Chances are you have heard about Python 2 and Python 3. Although they are two versions of the same language, they have different syntax; code written in Python 3 might not work in Python 2. So, let’s discover how you can check your Python version on the command line and in the script on Windows, macOS, and Linux systems.
Python is one of the most popular programming languages. With its simple syntax, high productivity, and amazing open-source libraries, Python can be used for just about anything.
However, you might have seen that some people use Python 2, while others prefer Python 3. The difference between these two versions is quite significant – it’s not just about fixing some bugs and adding a few new features. If the application is written in Python 2, you may not be able to run it using Python 3.
So, you should definitely know the version of Python installed on your computer. Let’s see how you can check the Python version. We’ll start with the command line.
Check Python Version: Command Line
You can easily check your Python version on the command line/terminal/shell. Let’s first recall how we can access the command line in different operating systems.
Windows
macOS
Linux
Then, for any of the operations systems above, you simply type python —version OR python -V, on the command line and press Enter . You’ll get a result like this:
python --version Python 3.8.3 python -V Python 3.8.3
Depending on your Python distribution, you may get more information in the result set. However, the number next to Python is the version number, which is what we are looking for. In this case, the full version number is 3.8.3.
Usually, we are interested in the major version – Python 2 or Python 3. This is indicated by the first number of the full version number. This number is 3 in our case, which means that we have Python 3 installed on our computer.
Starting from Python 3.6, you can also use python -VV (this is two Vs, not a W) to get more detailed information about your Python version:
python -VV Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]
Check Python Version: Script
Sometimes you may want to check the version of Python when you are coding an application (i.e. inside the script). This is especially useful when you have multiple Python versions installed on your computer. To check which Python version is running, you can use either the sys or the platform module. The script will be the same for Windows, macOS, and Linux.
To check the Python version using the sys module, write:
import sys print (sys.version)
# 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]
To check the Python version using the platform module, use the following code:
import platform print(platform.python_version())
The output will be as follows:
Both code snippets output the Python version in the string format. If necessary, you can also get the version number in the tuple format. The tuple will contain five components: major, minor, micro, release level, and serial:
print (sys.version_info) # sys.version_info(major=3, minor=8, micro=3, releaselevel='final', serial=0)
Of course, you can easily obtain the individual components of this tuple using an index (e.g. sys.version_info[0] ) or a name (e.g. sys.version_info.major ).
Pretty simple, right? No wonder Python is so popular.
Python 2 or Python 3?
Now we know how to check the Python version. But what’s the difference between the two versions?
Python 2 is an older version that was actively used in software development and IT operations (DevOps). However, it is no longer under development and has been discontinued starting from January 1, 2020. This implies that any bugs or security problems discovered in Python 2 are no longer being addressed by Python developers. Python’s volunteer developers advise that people using Python 2 move to Python 3 as soon as possible.
Python 3 was first introduced in 2008. It’s syntax and behavior is quite different from Python 2, but it’s generally believed that Python 3 is simpler and easier to understand.
As Python 2 is no longer supported, you should definitely choose Python 3 if you are writing a new application or just starting to learn Python. The only reason to learn Python 2 is if your company’s code is written in Python 2 and you need to work with it. This shouldn’t be often the case, especially once Python 2 has been discontinued for a while.
Time to Practice Python!
Do you want to learn Python 3? Join the track Learning Programming with Python on LearnPython.com, where you will be introduced to the fundamentals of programming – not just in theory but with over 400 interactive coding challenges.
The track starts with Python Basics: Part 1, a course that teaches students how to create the simplest Python applications. This course (and the track itself) are aimed at students with no prior IT background. If you are already familiar with Python’s basics, join one of the advanced courses on LearnPython.com and learn how to work with strings, JSON files, and CSV files in Python.
Professionals across different industries enjoy the benefits of this simple and effective programming language. You can join them very soon! It doesn’t take much time to become proficient in Python, especially if you plan your studying activities appropriately.
Thanks for reading, and happy learning!