如何检查哪个版本的Python解释器正在运行我的脚本?


当前回答

检查Python版本:Python -V或Python——version或apt-cache policy Python

你也可以运行whereis python查看安装了多少个版本。

其他回答

尝试使用os。Popen在变量中读取它:

import os
ver = os.popen('python -V').read().strip()
print(ver)

最简单的方法

只需在终端中输入python,就可以看到版本 就像下面这样

desktop:~$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

检查Python版本:Python -V或Python——version或apt-cache policy Python

你也可以运行whereis python查看安装了多少个版本。

有六个模块,你可以做到:

import six

if six.PY2:
  # this is python2.x
else:
  # six.PY3
  # this is python3.x

在Windows操作系统下,通过在命令提示符中输入以下命令,验证命令的Python版本

c:\>python -V
Python 2.7.16

c:\>py -2 -V
Python 2.7.16

c:\>py -3 -V
Python 3.7.3

此外,要查看每个Python版本的文件夹配置,请运行以下命令:

For Python 2,'py -2 -m site'
For Python 3,'py -3 -m site'