Hi,
I think the problem is that setting environment variables like
LD_LIBRARY_PATH will only affect subprocesses.
So you need to spawn a subprocess after doing so.
Here is an example of running Maya from and with the external
interpreter (only know about Linux way of doing so ) :
First you should have the following in a file named "sub.py" in a place
python can find it (where you started python from or in PYTHONPATH)
sub.py :
import os, sys
print "Python version:", sys.version
print "LD_LIBRARY_PATH:", os.environ['LD_LIBRARY_PATH']
print "sys.path:", sys.path
try :
import maya.standalone
maya.standalone.initialize()
print "maya is up!"
import maya.cmds as cmds
cmds.select(cmds.polySphere())
print
cmds.ls(selection=True)
except :
print "mayainit failed"
exit()
Then start a python shell and type :
Python 2.5.2 (r252:60911, May 7 2008, 15:21:12)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys, subprocess
>>> os.environ['LD_LIBRARY_PATH'] =
'/usr/autodesk/maya2008-x64/lib/'
>>> os.environ['PYTHONHOME']='/usr/lib/python2.5'
>>>
os.environ['PYTHONPATH']='/usr/autodesk/maya2008-x64/lib/python2.5:/usr/autodesk/maya2008-x64/lib/python25.zip:/usr/autodesk/maya2008-x64/lib/python2.5/lib-dynload:/usr/autodesk/maya2008-x64/lib/python2.5/site-packages'
>>> sub = subprocess.Popen(['python', 'sub.py'],
stdout=sys.stdout, stderr=sys.stdout)
>>> Python version: 2.5.2 (r252:60911, May 7 2008, 15:21:12)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]
LD_LIBRARY_PATH: /usr/autodesk/maya2008-x64/lib/
sys.path: ['/home/orenouard',
'/usr/autodesk/maya2008-x64/lib/python2.5',
'/usr/autodesk/maya2008-x64/lib/python25.zip',
'/usr/autodesk/maya2008-x64/lib/python2.5/lib-dynload',
'/usr/autodesk/maya2008-x64/lib/python2.5/site-packages',
'/usr/lib/python2.5/lib/python25.zip',
'/usr/lib/python2.5/lib/python2.5',
'/usr/lib/python2.5/lib/python2.5/plat-linux2',
'/usr/lib/python2.5/lib/python2.5/lib-tk',
'/usr/lib/python2.5/lib/python2.5/lib-dynload']
maya is up!
[u'pSphere1', u'polySphere1']
>>>
Note : sys.path += ['whatever'] would do no good in the caller
process as it won't be carried over, you can do it in the child process
though before importing any maya module.
There were minor compatibility issues when using an external
interpreter instead of Maya's one (especially since Ubuntu bumped it
from 2.5.1. to 2.5.2), but nothing big. Maya's own interpreter has its
own quirks like the inability to import md5 unless some library links
are provided, Chad posted a solution some time ago on that list.
Now you can also spawn Maya's own standalone interpreter directly (all
that the autodesk mayapy shell script does is setting the env var for
you), so that you actually run in Maya's provided Python version :
Python 2.5.2 (r252:60911, May 7 2008, 15:21:12)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys, subprocess
>>> os.environ['LD_LIBRARY_PATH'] =
'/usr/autodesk/maya2008-x64/lib/'
>>>
os.environ['PYTHONHOME']='/usr/autodesk/maya2008-x64/lib/python2.5'
>>>
os.environ['PYTHONPATH']='/usr/lib/python2.5:/usr/lib/python2.5/site-packages'
>>> sub =
subprocess.Popen(['/usr/autodesk/maya2008-x64/bin/python-bin',
'sub.py'], stdout=sys.stdout, stderr=sys.stdout)
>>> Python version: 2.5.1 (r251:54863, Jun 5 2007, 12:01:59)
[GCC 4.1.2]
LD_LIBRARY_PATH: /usr/autodesk/maya2008-x64/lib/
sys.path: ['/home/orenouard', '/usr/lib/python2.5',
'/usr/lib/python2.5/site-packages',
'/usr/autodesk/maya2008-x64/lib/python2.5/lib/python25.zip',
'/usr/autodesk/maya2008-x64/lib/python2.5/lib/python2.5',
'/usr/autodesk/maya2008-x64/lib/python2.5/lib/python2.5/plat-linux2',
'/usr/autodesk/maya2008-x64/lib/python2.5/lib/python2.5/lib-tk',
'/usr/autodesk/maya2008-x64/lib/python2.5/lib/python2.5/lib-dynload',
'/usr/local/lib/python2.5/site-packages']
maya is up!
[u'pSphere1', u'polySphere1']
>>>
Here the PYTHONPATH is used the other way round, to add the standard
system /usr/lib/python2.5/site-packages to path so that you can import
external extension in Maya's interpreter for instance
Of course both these are the same as doing it from a shell, it's just
if you want to run that from an already running python script /
session. I'ts actually easier to set LD_LIBRARY_PATH / PYTHONHOME /
PYTHONPATH before calling a python interpreter as you can avoid the
need to spawn a sub process :
orenouard@newhon:~$ export
LD_LIBRARY_PATH='/usr/autodesk/maya2008-x64/lib/'; python
Python 2.5.2 (r252:60911, May 7 2008, 15:21:12)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import maya.standalone
>>> maya.standalone.initialize()
>>>
I guess there should be a way to correctly redirect the stdin and
stdout of the subprocess to be able to get an interractive shell on the
subprocess but didn't find it...
Olivier