I think it's because os.environ is only update if you go through it to
modify env vars, as explained here :
http://docs.python.org/lib/os-procinfo.html
Wouldn't a os.getenv(varname) refresh it for a particular variable ? We
already parse Maya.env in mayainit (because otherwise the variable
settings happens too late for complete Python init), we could refresh
os.environ in the mayautils too.
Olivier
--
Olivier Renouard
Sounds good, must be careful that Maya's way of setting variables in
Maya.env is a bit peculiar too :
- some variables, if already set, won't be changed by a declaration in
Maya.env. Thus it sets them only if they were undefined (doesn't
overwrite).
- for the variables that are path, Maya adds the path declared in
Maya.env to them (because the syntax $PATH=$PATH:/usr/autodesk doesn't
work in Maya.env, I think to remember it just doesn't work on Linux and
it creates an endless loop on Windows)
- the reason for manually parsing Maya.env was so that it could be
parsed before initializing Maya. If you put there info like
LD_LIBRARY_PATH, it's too late to parse it after an init, as an init
won't be able to complete without properly setting this variable (that's
all the variables that are set before calling maya's executable in
Maya2008 shell script for instance). It is not strictly necessary but
thought it would be nice to regroup all variable declaration where
people are used to put them (Maya.env) so that you could start Maya by
just doing a "read Maya.env for the version of Maya that's being called,
call maya's executable".
This is I think what the startup shell Maya2008 should do instead of the
quite long bit of code that is actually in it, with a bunch of
overrides, custom declaration and layered addons. Besides, some custom
fixes (like lauching Maya with a different python interpreter or graphic
fixes like MAYA_MMSET_DEFAULT_XCURSOR 1 and XLIB_SKIP_ARGB_VISUALS 1on
linux) would require you to modify the Maya2008 script which is less
straightforward than allowing to place them with the rest in Maya.env.
Olivier
--
Olivier Renouard
I've bugged this and come up with a bit of a workaround...
The problem is that we are starting Maya inside of Python, instead of
in interactive where you are starting Python inside of Maya.
maya.standalone.initialize() should be doing more to transfer these
environment variables back up into Python.
One way I've worked around this goes like this:
On linux and mac:
./mayapy #double click the mayapy.exe on windows
import maya.standalone as ms
ms.initialize()
import os
os.system('csh') # use cmd on windows
./mayapy # just mayapy on windows
import maya.standalone as ms
ms.initilaize()
import os
os.environ.keys()
################
So, it's a bit strange, but here I am running Maya inside of Python
and then Python inside of Maya and then Maya inside of Python.
So there is a bit of a hit on the system. You might be able to save
the keys out and quit back into the first Maya inside of Python and
use os.environ[KEY] =maya.mel.eval('getenv KEY') for each KEY in keys.