我正在尝试设置 Eclipse IDE 以识别 maya.cmds 模块,以及与 maya 模块关联的所有模块。以下代码是在 Eclipse 和 Maya 的脚本编辑器中运行的测试。
import maya
print 'maya:\n', dir(maya)
from maya import cmds
print 'cmds:\n', len(dir(cmds)) # too many to print
print 'sphere: ', cmds.sphere
在 Maya 的脚本编辑器中,代码生成
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>
在 Eclipse 中,代码结果为
maya:
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
cmds:
6
sphere:
Traceback (most recent call last):
AttributeError: 'module' object has no attribute 'sphere'
我在谷歌组“python inside maya”和网络搜索中进行了大量搜索。我找到的最好的链接是以下链接,但这根本没有解决我的问题,最后给出了相同的结果。 http://www.luma-pictures.com/tools/pymel/docs/1.0/eclipse.html
我读过我应该在 Eclipse 中设置我的环境路径,而不是我的机器,我也读过相反的观点。我应该在 Eclipse 和/或 Windows 中设置什么环境变量,在哪里设置?
最佳答案
解决方法是导入maya.standalone并初始化。 这使您可以访问其中的 Maya 包和模块。
import maya.standalone
maya.standalone.initialize()
import maya
print 'maya:\n', dir(maya)
from maya import cmds
print 'cmds:\n', len(dir(cmds)) # too many to print
print 'sphere: ', cmds.sphere
输出:
maya:
['__builtins__', '__doc__', '__file__', '__name__', '__package__',
'__path__', 'app', 'cmds', 'mel', 'standalone', 'stringTable', 'test', 'utils']
cmds:
2945
sphere: <built-in method sphere of module object at 0xf33948>
关于python - Maya 的 python 模块的 Eclipse 环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4841190/