为python脚本设置默认解释器 [英] Setting default interpreter for a python script
问题描述
我使用的模块只能在python 2.7中找到,因此在运行脚本时,我必须指定 python2.7脚本
而不是仅脚本
。我知道那里还有更大的问题,但我仍然想知道-
是否可以在编写python脚本时将解释器默认设置为2.7?
也许可以通过设置#! / usr / bin / env python
例如?
I am using a module that can only be found in python 2.7, so when I run my script I have to specify python2.7 script
instead of just script
. I know there are bigger issues out there, but still I was wondering -
is it possible, when writing a python script, to set the interpreter to 2.7 by default?
Maybe by setting #! /usr/bin/env python
for example?
推荐答案
大多数Unix环境中的 python2.7
可执行文件,因此您可以编写:
Most unix environments will have the python2.7
executable, such that you can write:
#!/usr/bin/env python2.7
显然,这在Windows上没有太大帮助。您也可以至少在启动后检查python版本,尽管如果可用的话它将无法帮助您运行更高版本:
Obviously this doesn't help much on windows. You can also at least check the python version once you are started, although it won't help you run the later version if it is available:
import sys
print sys.version_info
...really do checks here...
这篇关于为python脚本设置默认解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!