如何检查哪个版本的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'
推荐文章
- 证书验证失败:无法获得本地颁发者证书
- 当使用pip3安装包时,“Python中的ssl模块不可用”
- 无法切换Python与pyenv
- Python if not == vs if !=
- 如何从scikit-learn决策树中提取决策规则?
- 为什么在Mac OS X v10.9 (Mavericks)的终端中apt-get功能不起作用?
- 将旋转的xtick标签与各自的xtick对齐
- 为什么元组可以包含可变项?
- 如何合并字典的字典?
- 如何创建类属性?
- 不区分大小写的“in”
- 在Python中获取迭代器中的元素个数
- 解析日期字符串并更改格式
- 使用try和。Python中的if
- 如何在Python中获得所有直接子目录