Note: Wing can interact with Maya in three different ways. This is one of the three. See an overview here on the whole system:
Interaction between Wing and Maya.
See
Wing Setup Notes below for how to setup Wing to use this information.
Maya comes with its own cut of Python (see
Python & Qt versions in Maya). The executable for that lives here on Windows:
c:\Program Files\Autodesk\Maya<version>\bin\mayapy.exe
Or here on Mac:
/Applications/Autodesk/maya<version>/Maya.app/Contents/bin/mayapy
You can execute this directly to launch an interactive prompt of Python (most commonly for batching purposes). Or, if you're running a Python IDE external to Maya, but you want Maya's Python calls to exist in it, you can point your IDE To that exe. There is often an option in your IDE to allow for this (Wing allows you to do this, for example).
Once that executable has been started, you still need load and initialize Maya into that session. Per Maya's docs: "
These commands take a significant amount of time to execute as they are loading all of the Maya's libraries and initializing the scene.
" This is the code I use:
try:
import maya.standalone
maya.standalone.initialize()
print "Imported maya.standalone\n"
except:
print "Couldn't find 'maya.standalone' for import\n"
If you want that code to execute
every time you launch Maya's version of Python (I do this in Wing), you can author the above code as a module, and point Python's
PYTHONSTARTUP
environment variable to it:
PYTHONSTARTUP = <somePath>\<somePythonStartupModule>.py
I have
Wing execute this code for my 'Maya Python coding sessions'.
The
maya.cmds()
library is actually empty on disk (go take a look for yourself) other than the
__init__.py
module that defines that dir structure
as a library:
C:\Program Files\Autodesk\Maya<VER>\Python\lib\site-packages\maya\cmds\
Although you can fully access all Maya commands through Python like '
maya.cmds.ls()
', the Python
ls()
command wrapper has no physical location on disk: Until you execute the above code example (
import maya.standalone
...), Python won't see any of the commands. If you want to get a better understanding, see the subject
How does Maya populate maya.cmds?.
Wing Setup Notes
- In Wing, create a new Project, and access the "Project Properties".
- In the Environment tab:
- Set "Python Executable" to "Custom", and browse to the path mentioned above with
mayapy.exe
in it. - Set "Environment" to "Add to inherited environment", and paste in the
PYTHONSTARTUP
path you authored above. - If you want Wing to be able to analyze your Maya-Python modules and give you functionality like "Go To Selected Symbol Definition" (ctrl+LMB on a symbol name, F4 hotkey on a symbol, etc), you can add the paths where they're stored to the "Python Path" section of the ui. If you're using Python's packaging system, you only need to add the root dir of each package to this field.
- Hit OK
- Be sure to "Save Project" ;)