简体   繁体   English

如何在较新的Python解释器中运行Python脚本?

[英]How do you run a Python script in a newer Python interpreter?

I am using several applications that are using different versions of Python: 我正在使用几个使用不同版本的Python的应用程序:

Nuke - 2.7 核弹-2.7

3Dequalizer - 2.6 3均衡器-2.6

linux - 2.6.6 Linux-2.6.6

I am getting various problems trying to get them all to communicate with one another, so I was wondering if it's possible to change Python interpreter during a script. 我遇到各种问题,试图让他们彼此之间进行交流,所以我想知道是否有可能在脚本过程中更改Python解释器。

Eg Start in 2.6, then run a Python script in 2.7 from a script in 2.6 例如从2.6开始,然后从2.6中的脚本运行2.7中的Python脚本

EDIT: 编辑:

nuke_install = "/path/to/nuke"

cmd = nukeLauncher + " -t"
os.system(cmd)

The -t flag allows for nuke to be run without a GUI. -t标志允许nuke在没有GUI的情况下运行。 This code works when run in a Python interpreter, but when I run via a Python script in 3dequalizer it gives me the: 这段代码在Python解释器中运行时有效,但是当我在3dequalizer中通过Python脚本运行时,它会为我提供:

ImportError: No module named site

To add another level of confusion, I can import site inside 3dequalizer. 为了进一步提高混乱程度,我可以在3dequalizer中导入网站。 The sys.path for 3dequalizer contains the same paths as when run directly from the interpreter, with a few additions for the python lib that comes with 3de. 3dequalizer的sys.path包含与直接从解释器运行时相同的路径,并为3de随附的python lib提供了一些附加功能。

Also PYTHONPATH is empty inside 3dequalizer. 在3dequalizer中,PYTHONPATH也为空。 Does this matter if sys.path is pointing to the right paths? 如果sys.path指向正确的路径,这有关系吗?

I am not sure it is really the way to go; 我不确定这是否真的可行; but if you really want to do it, you could use the os.system command with somthing like: 但是,如果您确实想这样做,则可以将os.system命令与os.system命令配合使用:

os.system("python2.7 myscript.py")

which will execute the program python2.7 (as long as it is in your executable path) with the name of the script as its argument (before returning to the current) statement in your initial script. 它将执行程序 python2.7(只要它在您的可执行路径中),并在初始脚本中使用脚本名称作为其参数(在返回当前值之前)。

But honestly, I think you should do it in some other way. 但老实说,我认为您应该以其他方式做到这一点。 Regards. 问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM