Home  >  Article  >  Backend Development  >  How to check Python version in shell script?

How to check Python version in shell script?

藏色散人
藏色散人Original
2019-04-22 17:31:184500browse

Python is a high-level general-purpose programming language created by Guido van Rossum. It was first released in 1991. Usually, Linux-based distributions already come with a pre-installed version of Python.

This tutorial will help you find the Python version details in your script. Additionally, you can ensure that your Python script only runs the smallest version found.

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 detailed version information using sys.version_info as shown below:

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

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

>>> sys.hexversion
 
50660080

Using Assert in Python

You can ensure that your script runs with the minimum version required by your application. For example, a Python application will terminate if it is running a lower version of the Python interpreter than required. Add the following code to your application:

assert sys.version_info >= (3, 5)

How to check Python version in shell script?

Related recommendations:《Python Tutorial

The above is the detailed content of How to check Python version in shell script?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn