• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How To Check Python Version In A Shell Script

Written by Rahul, Updated on April 12, 2019

Python is a high-level, general-purpose programming language created by Guido van Rossum. It was first released in 1991. Generally, Linux based distros have pre-installed Python version.

This tutorial will help you to find Python version details inside a script. Also, you can ensure a Python script to run only the minimum version found.

1
2
import sys
print(sys.version)

Output:

3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609]

You can also find the details version info by using sys.version_info like below:

1
2
3
>>> sys.version_info
 
sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)

Show the Python hex version details. This value increases with every release of python.

1
2
3
>>> sys.hexversion
 
50660080

Using Assert in Python

You can ensure a script runs with the minimal version required for your application. For example, if the Python application is running with a lower version of Python interpreter than required will be terminated. Add the following code to your application:

1
assert sys.version_info >= (3, 5)

Assertion Error Python

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How to View or List Cron Jobs in Linux
  • How to Install PHP 8 on Ubuntu 20.04
  • How to Set Up SSH Tunnel with PuTTY
  • How to Install MySQL 8.0 on Ubuntu 20.04
  • Issue with phpMyAdmin and PHP: Warning in ./libraries/sql.lib.php#613 count(): Parameter must be an array or an object that implements Countable”
  • How to Install Tor Browser on Ubuntu 20.04
  • How to Allow Remote Connections to MySQL
  • How To Install VNC Server on Debian 10
© 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy