pymel.internal.mayaInit

mayaInit(forversion=None)

Try to init Maya standalone module, use when running pymel from an external Python inerpreter, it is possible to pass the desired Maya version number to define which Maya to initialize

Part of the complexity of initializing maya in standalone mode is that maya does not populate os.environ when parsing Maya.env. If we initialize normally, the env’s are available via maya (via the shell), but not in python via os.environ.

Note: the following example assumes that MAYA_SCRIPT_PATH is not set in your shell environment prior to launching python or mayapy.

>>> import maya.standalone            
>>> maya.standalone.initialize()      
>>> import maya.mel as mm             
>>> print mm.eval("getenv MAYA_SCRIPT_PATH")    
/Network/Servers/sv-user.luma-pictures.com/luma .....
>>> import os                         
>>> 'MAYA_SCRIPT_PATH' in os.environ  
False

The solution lies in refreshEnviron, which copies the environment from the shell to os.environ after maya.standalone initializes.

Return type:bool
Returns:returns True if maya.cmds required initializing ( in other words, we are in a standalone python interpreter )

Previous topic

pymel.internal.loadCache

Next topic

pymel.internal.mayaStartupHasRun

Core

Core Modules

Other Modules

This Page