Skip to content

Commit f67e11f

Browse files
committed
Create check_python_version
check running python vers
1 parent cace904 commit f67e11f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

check_python_version

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// Use sys.version_info to check running python version
2+
def check_python():
3+
import sys
4+
info = sys.version_info
5+
ver_major = info.major
6+
ver_micro = info.micro
7+
ver_minor = info.minor
8+
ver_release = info.releaselevel
9+
ver_serial = info.serial
10+
if(ver_major not in [2,3]):
11+
print('Not python2 or python3,Please have a check!')
12+
sys.exit(1)
13+
if ver_major == 2:
14+
if ver_micro < 6:
15+
print('Python 2.6+ required,Please update your python version')
16+
sys.exit(1)
17+
if ver_major == 3:
18+
if ver_micro < 3:
19+
print('Python 3.3+ required,Please update your python version')
20+
sys.exit(1)
21+
print('Running python version info: \n'+info.__repr__())
22+
23+
if __name__ == '__main__':
24+
check_python()

0 commit comments

Comments
 (0)