From: "Mr. Daniel Browne" <dbrowne@(email surpressed)>
Subject: Re: CentOS 6 Python error
   Date: Tue, 12 Mar 2013 16:51:00 -0400
Msg# 2299
View Complete Thread (19 articles) | All Threads
Last Next
The solution I ultimately found was to set 

export PYTHONHOME=/usr/autodesk/maya2013-x64

within maya's os.system() call before the external python script is executed, then within the script un-set it or set it back to /usr/ before the rest of the imports are executed. None of the PYTHONPATH related solutions worked.


On Mar 12, 2013, at 1:45 PM, Greg Ercolano wrote:

[posted to rush.general]

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)


----------
Dan "Doc" Browne
System Administrator
Evil Eye Pictures

dbrowne@(email surpressed)
Office: (415) 777-0666 x105


Last Next