日期:2014-05-16  浏览次数:20613 次

linux下获取python的版本号【备忘】

?

1、在Linux命令行底下可以通过python -V查看python版本号
python -V 2>&1 | awk '{print $2}'

?

2、直接在命令行底下输入
$python
则返回以下内容,也可以“肉眼”获得python的版本号
Python 2.5.1 (r251:54863, Apr 28 2009, 18:32:15)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

?

3、通过python的platform模块获取版本号
$python -c 'import platform; print platform.python_version()'
2.5.1

?

4、通过python的sys模块获取版本号
$python -c 'import sys; print sys.version' 2>&1
2.5.1 (r251:54863, Apr 28 2009, 18:32:15)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)]
可以通过提取相应字段获取版本号
$python -c 'import sys; print sys.version' 2>&1 | awk '$1~/[0-9]\.[0-9].*/{print $1}'

?