查看系统上安装了哪些版本的python:

$ls /usr/bin/python*
/usr/bin/python  /usr/bin/python2  /usr/bin/python2.7  /usr/bin/python3  /usr/bin/python3.6  /usr/bin/python3.6m  /usr/bin/python3m
如何检查python版本

使用命令行检查python版本

Python 2

$/usr/bin/python -V
OR
/usr/bin/python --version
Python 2.7.15rc1

Python 3

$/usr/bin/python3 -V
OR
/usr/bin/python3 --version
Python 3.6.5

使用解释器检查Python版本

Python 2

$python
Python 2.7.15rc1 (default, Apr 15 2015, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.python_version()
'2.7.15rc1'
>>>

Python 3

$python3
Python 3.6.5 (default, Apr  1 2015, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.python_version()
'3.6.5'
>>>

使用脚本检查python版本

以下脚本将检查Python版本并将版本号打印到标准输出。

check-python-version.py :

import platform
python_version=platform.python_version()
print (python_version)

执行:

$python check-python-version.py 
2.7.15rc1
日期:2020-07-07 20:54:36 来源:oir作者:oir