怎样判断当前py文件在什么版本的python环境下运行
2个回答
2015-03-29 · 知道合伙人影视综艺行家
关注
展开全部
查下manual就可以知道了,有多个类似变量可用
sys.version
A string containing the version number of the Python interpreter plus additional information on the build number and compiler used. This string is displayed when the interactive interpreter is started. Do not extract version information out of it, rather, use version_info and the functions provided by the platform module.
如果是给人读,用 sys.version,
如果是给机器比较,用 sys.version_info,
如果是判断是不是 PyPy 等第三方实现,用 sys.implementation(要 Python 3.3)。
例子:
import sys
if sys.version_info < (3, 4):
raise RuntimeError('At least Python 3.4 is required')
sys.version
A string containing the version number of the Python interpreter plus additional information on the build number and compiler used. This string is displayed when the interactive interpreter is started. Do not extract version information out of it, rather, use version_info and the functions provided by the platform module.
如果是给人读,用 sys.version,
如果是给机器比较,用 sys.version_info,
如果是判断是不是 PyPy 等第三方实现,用 sys.implementation(要 Python 3.3)。
例子:
import sys
if sys.version_info < (3, 4):
raise RuntimeError('At least Python 3.4 is required')
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询