简体   繁体   中英

How do you run a Python script in a newer Python interpreter?

I am using several applications that are using different versions of Python:

Nuke - 2.7

3Dequalizer - 2.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.

Eg Start in 2.6, then run a Python script in 2.7 from a script in 2.6

EDIT:

nuke_install = "/path/to/nuke"

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

The -t flag allows for nuke to be run without a GUI. This code works when run in a Python interpreter, but when I run via a Python script in 3dequalizer it gives me the:

ImportError: No module named site

To add another level of confusion, I can import site inside 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.

Also PYTHONPATH is empty inside 3dequalizer. Does this matter if sys.path is pointing to the right paths?

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("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.

But honestly, I think you should do it in some other way. Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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