On 03/12/13 13:25, Greg Ercolano wrote:
> Sounds like the simple solution is to bracket all calls to os.system() with code
> that first preserves the current environment variables, then changes the PYTHONPATH
> (and whatever else) to what the OS's version of python needs. e.g.
>
> ppsave = os.environ["PYTHONPATH"]
> os.system(your_cmd)
> os.environ["PYTHONPATH"] = ppsave
Oops, forgot to add a line that /changes/ the PYTHONPATH to
whatever you want PYTHONPATH to be when your_cmd is running.
Also, it might be best to make that code a bit more robust,
protecting it from a situation where PYTHONPATH /isn't/ set, e.g.
# SAVE OLD PYTHONPATH
if os.environ.has_key("PYTHONPATH"): ppsave = os.environ["PYTHONPATH"]
else: ppsave = None
# CHANGE TO WHAT OS WANTS
os.environ["PYTHONPATH"] = "/what/you/want"
# INVOKE UNIX COMMAND
os.system(your_cmd)
# RESTORE PYTHONPATH
if ppsave != None: os.environ["PYTHONPATH"] = ppsave
else: del os.environ["PYTHONPATH"]
This way you can safely set PYTHONPATH just for your unix command
to run, then it changes it back so that maya has what it needs to
run normally.
Note: in my case, my OS's version of python works well with PYTHONPATH
completely unset. If that's what yours needs too, then change the above
line below 'CHANGE TO WHAT OS WANTS' to instead be:
# CHANGE TO WHAT OS WANTS
if os.environ.has_key("PYTHONPATH"): del os.environ["PYTHONPATH"]
This will make sure that variable is /unset/ before calling os.system()
so that the OS version of python won't see it set, and will use its own
defaults. (Probably better than trying to guess what those defaults are)
--
Greg Ercolano, erco@(email surpressed)
Seriss Corporation
Rush Render Queue, http://seriss.com/rush/
Tel: (Tel# suppressed)ext.23
Fax: (Tel# suppressed)
Cel: (Tel# suppressed)
|