![]()
Python from an external interpreter
![]()
In addition to supporting Python within the Maya application, Maya also supports using the Python modules of Maya from a standalone Python interpreter. This is useful when doing batch processing, or when accessing the functionality of Maya from another application that uses Python (such as MotionBuilder or Toxik).
We provide a standalone Python interpreter which is configured correctly for importing Maya functionality.
- On Windows and Linux, run the
mayapyexecutable from thebindirectory of Maya.- On Mac OS X, run the
mayapyexecutable from
../ Maya.app/Contents/bin.Once the python interpreter is loaded, Maya must be loaded and initialized. To do so, type the following in the window:
import maya.standalone
maya.standalone.initialize( name='python' )
Note
These commands take a significant amount of time to execute as they are loading all of the Maya's libraries and initializing the scene.
The initialize routine takes only one parameter (
name), and it is optional. Thenameparameter tells Maya what the name of the application is. The default value fornameispython.Once Maya is loaded and initialized, all Maya functionality should be available (
maya.cmds,maya.OpenMaya, and so on). However, running Maya inside a Python interpreter is equivalent to running Maya in batch mode. That means that all normal Maya batch mode restrictions are in place, including the disabling of the UI commands.Using a different Python interpreter
It is possible to use Maya from a Python interpreter other than the one that ships with Maya. However, it is recommended that you use the same version number of Python as is included in Maya. To use another interpreter, it is necessary to set up the correct environment.
To set up the environment for a Python interpreter
- Add the
site-packagesdirectory of Maya to your PYTHONPATH environment variable, or add it to sys.path inside of Python once the interpreter is initialized (but before Maya is initialized).This directory is:
- Windows: .
./Python/Lib/site-packages- Mac OS X:
../Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.4/site-packages- Linux:
../lib/python2.4/site-packages- Set the MAYA_LOCATION environment variable to point to Maya's install location, so that Maya can find its resources.
On Mac OS X, the MAYA_LOCATION must be set to point into the application bundle (that is,
../Maya.app/Contents).
- (Linux) Add the
libdirectory of the Maya distribution to the LD_LIBRARY_PATH so that Python can find the shared libraries when importing Maya.