Eclipse environment for Maya's python modules

I’m trying to set up the Eclipse IDE to recognize the maya.cmds module, an all modules associated with the maya module. The following code are tests run in Eclipse, and Maya’s script editor.

    import maya
    print 'maya:
', dir(maya)
    
    from maya import cmds
    print 'cmds:
', len(dir(cmds)) # too many to print
    
    print 'sphere: ', cmds.sphere

In Maya’s script editor the code results in

    maya:
    ['OpenMaya', '_OpenMaya', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'app', 'cmds', 'mel', 'standalone', 'stringTable', 'utils']

    cmds:
    3190
    
    sphere: <built-in method sphere of module object at 0x0000000019F0EEE8>

In Eclipse the code results in

    maya:
    ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']

    cmds:
    6
    
    sphere: 
    Traceback (most recent call last):
    AttributeError: 'module' object has no attribute 'sphere'

I’ve done a lot of searching, on the google group “python inside maya”, and web searches. The best I’ve found was the following link, however this did not solve my issue at all, and in the end gave the same result. [http://www.luma-pictures.com/tools/pymel/docs/1.0/eclipse.html]

I’ve read that I should be setting my environment paths in Eclipse, rather than my machine, and I’ve also read the opposite opinion. What environment vars should I set, to where, and in Eclipse, Windows, or both?

Quick tip. ‘maya’ is not a module, but a package. The module ‘cmds’ unfortunately is not a python source module. It’s compiled. In order for Eclipse to import the module and make the classes/methods available as, say auto-completed code, you’ll need to use something like PyMEL. That said, PyMEL is the perfect solution. PyMEL in any form, implemented in 2011, or installed with 2009, includes an ‘extras’ package folder that is purposed for autocompletion.

Hope that helps…

PyMEL’s installation documentation actually outlines the basic steps for setting up autocompletion in Eclipse.

I’ve found the solution, to get this to work you simply need to do the following before the import maya.cmds as cmds line

import maya.standalone
maya.standalone.initialize()

import maya.cmds as mc
print mc.sphere
  • results in the sphere function
print dir(mc)
  • results in all the maya.cmds