•  Home
  •  Dashboard
  •  Company
    • About Us
    • Blog
    • Careers
    • Contact Us
    • Data Centers
    • Looking Glass
    • Network
    • Reseller
  •  Hosting Services
    • Backup
    • Content Delivery Network
    • Colocation Hosting
    • Dedicated Hosting
    • DDoS Mitigation
    • IP Transit
    • Private Cloud
    • Wavelength
  •  Solutions
    • Ecommerce
    • Finance
    • Gaming
    • Hosting
    • Management
    • Security
    • System Integrator
  •  Support
    • Community
    • Knowledge Base
    • Open A Ticket
  •  USA & Canada: 800-933-1517
  •  International: 626-549-2801
  •  Email: sales@psychz.net
  • Services
    • Dedicated Servers
    • Colocation
    • Private Cloud
    • DDos Protection
    • IP Transit
    • CDN
    • Backup
  • Solutions
    • Ecommerce
    • Security
    • Gaming
    • Hosting
    • Management
    • Finance
    • System Integrator
  • Dashboard

How to Check Python Version on a Linux machine?

  • Home
  • Client
  • Qa Forum
  • How to Check Python Version on a Linux machine?

Posted By: Dong | 1 Replies | Last Reply On: Jun 30, 2021 11:12:51

I have recently installed Python3 on a fresh CentOS 8 VPS. I intend to use this for a development environment. I was wondering how to check the version of Python installed.

Psychz - Sandip

Votes: 0Posted On: Jun 30, 2021 11:12:51
 

Python is an object-oriented, interpreted, high-level programming language with dynamic semantics. Python's simple, easy-to-learn syntax emphasizes readability and therefore reduces the cost of program maintenance. It supports modules and packages, which encourages program modularity and code reuse. There are different Python versions, but the two most popular ones are Python 2.7.x and Python 3.7.x. The x stands for the revision level and could change as new releases come out.
 
When looking at the version number, there are usually three digits to read:
 
 major version    (X.0.0)
 minor version    (0.X.0)
 micro version     (0.0.X)

 
While major releases are not fully compatible, minor releases generally are. Version 3.6.1 should be compatible with 3.7.1, for example. The final digit signifies the latest patches and updates.
 
When using Python, it is essential to know which version an application requires and which version you have. Today, there are two active versions of Python: Python 2 and Python 3, of which Python 2 is no longer supported from January 2020.
To verify the version of Python3, please use the following command.

[root@centos-8 /]# python3 --version

Output

Python 3.6.8


Check Python Version in Script
 
When writing an application, it is helpful to have the software check the version of Python before it runs to prevent crashes and incompatibilities.

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 >= 6:
 
    print("Python 3.6 or higher is required.")
 
    print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))
 
    sys.exit(1)

When this script runs, it will test to see if Python 3.6 is installed on the system. If not, it will send a notification and displays the current Python version.

 

Conclusion
 
We hope you have a good understanding of how to check for Python installed in several different operating systems. Python is a powerful programming language. Thus it's essential to understand its various versions. Please vote us if you like this article.

Was this reply helpful?

Related topics

  • How to check Python version in Windows?
  • How to check Centos Version?
  • Someone from your IP trying to gain access to my vDSL modem?
  • Is there any ARM version of CentOS?
  • Is Centos 8 the last stable OS release?
  • Security token intro
  • Psychz CDN Products and Features Updates
  • Secure Token Integration For Python (Secondary)
  • Secure Token Integration For Python
  • Scientific Linux and its features
  • What Scientific Linux is and its features
  • Top Useful Features Of Linux Mint
  • How To Install Git On Centos 7
  • How To Run Kubernetes on Psychz Networks Bare Metal Servers
  • Top Antivirus programs for Linux
Hosting Services
  • Dedicated Hosting
  • Colocation Hosting
  • Backup
  • IP Transit
  • DDoS Mitigation
Support
  • Portal Login
  • Knowledgebase
  • Community
Company
  • About Us
  • Contact Us
  • Network
  • Data Centers
  • Looking Glass
  • Affiliates
  • Reseller
  • Blog
Policies
  • Privacy Policy
  • Acceptable Usage Policy
  • Terms and Conditions
  • Service Level Agreement
Company
  • Psychz Networks,
    A Profuse Solutions Company
    611 Wilshire Blvd #300
    Los Angeles,California 90017
    USA
  • US/Canada: 800-933-1517
  • International: 626-549-2801
Subscribe to Our Mailing List
* indicates required
Copyright © 2023 Psychz Networks, A Profuse Solutions Inc Company