Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Check Python Version - DesignLinux

Aug 21 2020
designlinux 0 Comments
Check Python Version

Python is one of the popular programming language. It is used for machine learning, analyzing data, websites and more. Sometimes, for developing it’s required to determine version of Python whether it is supported or not. In this article we will show you how to check the version of Python is installed on your system.

Python Version#

There are different versions of Python, but the two most popular ones are Python 2.7.x and Python 3.7.x.

Python uses semantic versioning. When looking at the version number, there are usually three digits to read:

MAJOR.MINOR.MICRO

For example, in Python 3.7.2, 3 is major version, 6 is a minor version, and 8 is a micro version.

  • MAJOR – Python 2 and Python 3 are major versions that are not fully compatible. For instance, 3.5.7, 3.7.2, and 3.8.0 are all part of the Python 3 major version.
  • MINOR – These releases are with new features and functions. For example, 3.6.6, 3.6.7, and 3.6.8 are all part of the Python 3.6 minor version.
  • MICRO – The new micro versions contain various bug fixes and improvements.

How to Check Python Version in Linux#

Currently, most modern Linux distributions and macOS comes with Python pre-installed. For Windows, you should download and install it.

To check which version is installed on your system, open terminal on your system and run the python --version or python -V command:

python --version

In output, it will print default Python version of your system. On this system it’s 3.7.8. It may be different version on your system.

For development the default version of Python will be used. Sometimes multiple Python versions are installed on a single system. If you have Python 3 installed you can check by typing:

python3 --version
Python 3.7.8

Python 2 support ends in 2020. Python 3 is the present and future of the language.

At the time of writing this article, the latest major release of the Python is version 3.8.x. Chances are that you have an older version of Python 3 installed on your system.

Check Python Version using Script#

Software that’s written in one version often will not work correctly in another version. When using Python, it is essential to know which version an application requires, and which version you have.

Generally, it is recommended to have the software check the version of Python before it runs to prevent crashes and incompatibilities.

Let’s make a script to check the version that requires at least Python version 3.7, and you want to check whether the system meets requirements. You can do that by simply checking the major and minor versions:

Use the following code snippet to check for the correct version of Python:

import sys

if not (sys.version_info.major == 3 and sys.version_info.minor >= 7):
    print("This script requires Python 3.7 or higher!")
    print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))
    sys.exit(1)

When the script runs, it will first check for the version of Python and if the version is less than 3.7 it will show following output:

This script requires Python 3.7 or higher!
You are using Python 2.7.

Conclusion#

In this article explained how to check the Python version.

If you have any question or suggestion, please leave a comment below.

Related

Tags: python, terminal

500 Internal Server Error

Prev Post

How to Install Tor Browser on Ubuntu 20.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 1,161
  • 568,825

DesignLinux.com © All rights reserved

Go to mobile version