How to check Python version in shell script?

藏色散人
Release: 2019-04-22 17:31:18
Original
4570 people have browsed it

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)
Copy after login

Output:

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

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)
Copy after login

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

>>> sys.hexversion
 
50660080
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template