How to reference maya commands in PyCharm?

2019-02-15 23:06发布

I am trying to get pycharm (latest community edition) working with maya 2015. And the very first thing I need is to be able to reference maya commands module, but I don't seem to be able to find how.

import maya.cmds as cmds

fails with

ImportError: No module named maya.cmds

What do I need to do to get it to work?

标签: pycharm maya
1条回答
狗以群分
2楼-- · 2019-02-15 23:30

I'm on Mac, but the steps should be the same on Windows, only some paths will differ.

Setup the Maya Python interpreter in Pycharm

  1. In Pycharm, open your preferences and find Project Interpreter.
  2. Next to the drop-down list, click the little [...] icon, and choose Add Local.
  3. Locate mayapy.exe or mayapy depending on your system. This is found in the bin folder in your Maya installation directory. On Mac it's located under .../Autodesk/maya2016.5/Maya.app/Contents/bin/mayapy

To make completions work

  1. Download the Maya developer kit (Google will help you) and extract it to a meaningful location.
  2. Click the [...] next to the drop-down list again and select More....
  3. Select your newly added interpreter from the steps above, it will be named something like Python 2.7.6 (/path/to/mayapy)

  4. Click the Paths button in the bottom toolbar
    Pycharm Interpreter Toolbar

  5. Click the + sign and locate the folder where you extracted the developer kit. Then navigate to .../devkit/other/pymel/extras/extras/completion/py/ and hit OK.



You should have a working setup with completion.

Based on information from this forum topic.

Edit: If you find it is still not working, ensure you go back into the paths for the interpreter (outlined above), look for, and select, a path called .../Python/Lib/site-packages and remove this file (press the - button). This information is also outlined in the above forum link.

查看更多
登录 后发表回答