I’m attempting to get my Python IDE (PyCharm) to code complete Maya Python API 2.0 objects. Since I’m working in the mayapy.exe environment, and including “C:\Program Files\Autodesk\Maya2016\devkit\other\pymel\extras\completion\py\maya” as an additional environment path, I’m getting good solid code completion for all my Maya.cmds and PyMEL objects. Since Pymel is using Maya’s Python API 1.0, I’m getting code completion for that API as well, but for Maya Python API 2.0, I get nothing. I’ve googled, and tried all kind of tricks, including typing up my custom code-complete skeleton files which literally involves me typing up the whole API 2.0 object model hierarchy into doc strings. Although that works, that’s not going to happen – I will have died of old age before getting half way done.
Any pointers? Solutions?
Solved! Go to Solution.
I’m attempting to get my Python IDE (PyCharm) to code complete Maya Python API 2.0 objects. Since I’m working in the mayapy.exe environment, and including “C:\Program Files\Autodesk\Maya2016\devkit\other\pymel\extras\completion\py\maya” as an additional environment path, I’m getting good solid code completion for all my Maya.cmds and PyMEL objects. Since Pymel is using Maya’s Python API 1.0, I’m getting code completion for that API as well, but for Maya Python API 2.0, I get nothing. I’ve googled, and tried all kind of tricks, including typing up my custom code-complete skeleton files which literally involves me typing up the whole API 2.0 object model hierarchy into doc strings. Although that works, that’s not going to happen – I will have died of old age before getting half way done.
Any pointers? Solutions?
Solved! Go to Solution.
Solved by robotProdigy. Go to Solution.
Ok, I have a working work-around (and it is a work-around). Even though I'm accepting this post as a solution, I hope Autodesk can include the necessary files in the Maya install at some point so that we get the same auto-complete we get from Maya.cmds and Maya Python API 1.0.
Before the work-around, let me clear something up. There is no need to include an additional environment path in PyCharm in order for it to "see" maya.cmds and maya.OpenMaya. It will do it by default once you set the Python environment to mayapy.exe.
Now - How to get PyCharm to "see", or auto-complete, for Maya Python API 2.0 classes e.g. maya.api.OpenMaya, vs maya.OpenMaya which is API 1.0. This requires modifying 4 files, and has not caused any problems on my end (so far), so take this as an "as is" solution. Also, if you're using Maya 2016, there is a prerequisite - download and install Maya 2016 devkit. If you're using 2015, you already have it. Also, I am using Windows 10, and Maya lives on my C, so bear that in mind if you're using OSX or working off your D drive, etc.
from _OpenMaya_py2 import *
from _OpenMayaAnim_py2 import *
from _OpenMayaRender_py2 import *
from _OpenMayaUI_py2 import *
I'll update this post if I find any issues, but again, this is working pretty well as of now. Please let me know if this is producing problems, because I would like to know.
Cheers,
Paul W
Ok, I have a working work-around (and it is a work-around). Even though I'm accepting this post as a solution, I hope Autodesk can include the necessary files in the Maya install at some point so that we get the same auto-complete we get from Maya.cmds and Maya Python API 1.0.
Before the work-around, let me clear something up. There is no need to include an additional environment path in PyCharm in order for it to "see" maya.cmds and maya.OpenMaya. It will do it by default once you set the Python environment to mayapy.exe.
Now - How to get PyCharm to "see", or auto-complete, for Maya Python API 2.0 classes e.g. maya.api.OpenMaya, vs maya.OpenMaya which is API 1.0. This requires modifying 4 files, and has not caused any problems on my end (so far), so take this as an "as is" solution. Also, if you're using Maya 2016, there is a prerequisite - download and install Maya 2016 devkit. If you're using 2015, you already have it. Also, I am using Windows 10, and Maya lives on my C, so bear that in mind if you're using OSX or working off your D drive, etc.
from _OpenMaya_py2 import *
from _OpenMayaAnim_py2 import *
from _OpenMayaRender_py2 import *
from _OpenMayaUI_py2 import *
I'll update this post if I find any issues, but again, this is working pretty well as of now. Please let me know if this is producing problems, because I would like to know.
Cheers,
Paul W
Hello, I am trying to follow your footsteps but no luck on my side. That said I am in a Mac environment and use Maya 2017.
1. In regards to step 1, the files are not empty. I tried it with and without the lines added.
2. after that I followed your steps, but the auto-completion won't work for me passed the import line (see image)
I tried also to follow https://vimeo.com/149598498
thanks for the help.
Hello, I am trying to follow your footsteps but no luck on my side. That said I am in a Mac environment and use Maya 2017.
1. In regards to step 1, the files are not empty. I tried it with and without the lines added.
2. after that I followed your steps, but the auto-completion won't work for me passed the import line (see image)
I tried also to follow https://vimeo.com/149598498
thanks for the help.
Too bad you're having issues on your end.
So I tried setting this all back up on my end, and I absolutely cannot get code completion to work on anything. Not maya.cmds, pymel.core, OpenMaya, etc. When I wrote the original doc, I was using an earlier version of PyCharm 2016. I'm now on PyCharm 2016.2.3. I'm not sure if the issue is there, or I'm overlooking something on my end. Pretty frustrating.
-Paul
Too bad you're having issues on your end.
So I tried setting this all back up on my end, and I absolutely cannot get code completion to work on anything. Not maya.cmds, pymel.core, OpenMaya, etc. When I wrote the original doc, I was using an earlier version of PyCharm 2016. I'm now on PyCharm 2016.2.3. I'm not sure if the issue is there, or I'm overlooking something on my end. Pretty frustrating.
-Paul
OK I got a little further on my end.
After removing this from my interpreter path:
C:\Program Files\Autodesk\Maya2016\Python\Lib\site-packages
And adding this to my interpreter path:
C:\Program Files\Autodesk\Maya2016\devkit\other\pymel\extras\completion\py
I got my maya.cmds and pymel.core auto completing. The reason (I think) is that the site-packages path contained a maya.cmds __init__.py file that was empty while the ...completion\py contained a maya.cmds __init__.py file with content which populates PyCharm auto complete widget.
For it all to make better sense, take a look at the image. Take a minute to digest it. PyCharm pulls code completion data from the Interpreter Paths specified for your interpreter which of course is mayapy. Notice how the directories/files listed in the Interpreter Paths window below show up in the External Libraries tree on the left. The ...\extras\completeion\py Interpreter Path is listed as py in the External Libraries tree. Since there is a listRelatives() function in the cmds module which is inside the maya module under the ...\extras\completeion\py directory, PyCharm is able to auto-complete on the right.
So you can find the maya/api/OpenMaya __init__.py file, in the External Libraries tree, look inside, that might be telling of what's going on. If it's an empty file, OpenMaya won't auto complete. OR if there is another directory in your External Libraries tree that also has a maya/api/OpenMaya __init__.py file, it could be overriding your good OpenMaya __init__ file. That's what was happening with my maya.cmds earlier in the post.
So if you're following on this, it maybe a matter of tweaking things a little different on your mac to get things up and running. Pain in the butt, obviously, but it might be possible if you're persistent with it with a touch of OCD ![]()
-Paul
OK I got a little further on my end.
After removing this from my interpreter path:
C:\Program Files\Autodesk\Maya2016\Python\Lib\site-packages
And adding this to my interpreter path:
C:\Program Files\Autodesk\Maya2016\devkit\other\pymel\extras\completion\py
I got my maya.cmds and pymel.core auto completing. The reason (I think) is that the site-packages path contained a maya.cmds __init__.py file that was empty while the ...completion\py contained a maya.cmds __init__.py file with content which populates PyCharm auto complete widget.
For it all to make better sense, take a look at the image. Take a minute to digest it. PyCharm pulls code completion data from the Interpreter Paths specified for your interpreter which of course is mayapy. Notice how the directories/files listed in the Interpreter Paths window below show up in the External Libraries tree on the left. The ...\extras\completeion\py Interpreter Path is listed as py in the External Libraries tree. Since there is a listRelatives() function in the cmds module which is inside the maya module under the ...\extras\completeion\py directory, PyCharm is able to auto-complete on the right.
So you can find the maya/api/OpenMaya __init__.py file, in the External Libraries tree, look inside, that might be telling of what's going on. If it's an empty file, OpenMaya won't auto complete. OR if there is another directory in your External Libraries tree that also has a maya/api/OpenMaya __init__.py file, it could be overriding your good OpenMaya __init__ file. That's what was happening with my maya.cmds earlier in the post.
So if you're following on this, it maybe a matter of tweaking things a little different on your mac to get things up and running. Pain in the butt, obviously, but it might be possible if you're persistent with it with a touch of OCD ![]()
-Paul
Thank you so much for your help. I will give a try.
Thank you so much for your help. I will give a try.
Thanks for the explanation, it works now.
Thanks for the explanation, it works now.
Hey I did everything done in this post like the other guy my files weren't empty so i skipped the first step and this is what it looks nice if you found a way to make it work please share
Hey I did everything done in this post like the other guy my files weren't empty so i skipped the first step and this is what it looks nice if you found a way to make it work please share
Hey Nazuko,
I looked over my instructions, and in step 3, I didn't explicitly state that you should pick mayapy.exe as the interpreter, although it does show it in the image. If that slipped by you, maybe that's all you need to get it to work. What version of Maya are you using? I haven't tried this on Maya 2017 yet, so not sure if there are any caveats.
Hey Nazuko,
I looked over my instructions, and in step 3, I didn't explicitly state that you should pick mayapy.exe as the interpreter, although it does show it in the image. If that slipped by you, maybe that's all you need to get it to work. What version of Maya are you using? I haven't tried this on Maya 2017 yet, so not sure if there are any caveats.
I'm using maya 2017 and yeah I was just following the image. What would I point it to then? do I install python 2.7 and point it to that? it made sense to me to point it to mayapy.exe like the steps.
I'm using maya 2017 and yeah I was just following the image. What would I point it to then? do I install python 2.7 and point it to that? it made sense to me to point it to mayapy.exe like the steps.
Yes, keep it pointed to mayapy.exe
I would be taken aback if installing Python 2.7 would somehow make this work, but I've seen stranger things. I'm not sure what the solution is to get yours to work. It's possible stephanosterburg6SYHS had the same problem you are and got passed it, possibly after taking into consideration my response to him.
Best of luck.
Yes, keep it pointed to mayapy.exe
I would be taken aback if installing Python 2.7 would somehow make this work, but I've seen stranger things. I'm not sure what the solution is to get yours to work. It's possible stephanosterburg6SYHS had the same problem you are and got passed it, possibly after taking into consideration my response to him.
Best of luck.
I got it to partly work and only some stuff works like import maya.cmds doesnt work but import pymel.core lists correctly and its strange, but
import maya.cmds as cmds << this line on the maya. << cmds or any maya stuff doesn't pop up, but
cmds. << all the cmds stuff like sphere and add pop up. no document stuff pop up at all, but at least it's slightly better then before. I'll look into the cmds folder to see what's up with it .
I got it to partly work and only some stuff works like import maya.cmds doesnt work but import pymel.core lists correctly and its strange, but
import maya.cmds as cmds << this line on the maya. << cmds or any maya stuff doesn't pop up, but
cmds. << all the cmds stuff like sphere and add pop up. no document stuff pop up at all, but at least it's slightly better then before. I'll look into the cmds folder to see what's up with it .
Since I have to do this anyway, I spent some time getting my PyCharm auto-completing for Maya 2017.
I followed my own instructions, and had some trouble because I didn't remove site-packages from my interpreter paths - although this is mentioned by myself a bit further down the thread. If you haven't done this yet, be sure and remove that path (below).
Also, for Maya 2017, those 4 files mentioned in step 1 of the instructions of course are no longer empty. I simply added the content I would have added to the empty 2016 version of those files. For example, for OpenMaya.py, I added from _OpenMaya_py2 import * under the docstring like so
"""
# Copyright 2012 Autodesk, Inc. All rights reserved.
#
# Use of this software is subject to the terms of the Autodesk
# license agreement provided at the time of installation or download,
# or which otherwise accompanies this software in either electronic
# or hard copy form.
"""
from _OpenMaya_py2 import *
class MFloatVector(object):
bla bla bla...I can't rule out that adding these wild-card imports won't make something somewhere else unhappy, but at the moment, I can't imagine what.
Now my Pycharm is auto-completing for maya.cmds, pymel.core, Python API1, and Python API2.
Hope this helps.
Since I have to do this anyway, I spent some time getting my PyCharm auto-completing for Maya 2017.
I followed my own instructions, and had some trouble because I didn't remove site-packages from my interpreter paths - although this is mentioned by myself a bit further down the thread. If you haven't done this yet, be sure and remove that path (below).
Also, for Maya 2017, those 4 files mentioned in step 1 of the instructions of course are no longer empty. I simply added the content I would have added to the empty 2016 version of those files. For example, for OpenMaya.py, I added from _OpenMaya_py2 import * under the docstring like so
"""
# Copyright 2012 Autodesk, Inc. All rights reserved.
#
# Use of this software is subject to the terms of the Autodesk
# license agreement provided at the time of installation or download,
# or which otherwise accompanies this software in either electronic
# or hard copy form.
"""
from _OpenMaya_py2 import *
class MFloatVector(object):
bla bla bla...I can't rule out that adding these wild-card imports won't make something somewhere else unhappy, but at the moment, I can't imagine what.
Now my Pycharm is auto-completing for maya.cmds, pymel.core, Python API1, and Python API2.
Hope this helps.
I added those lines, but when I type import maya. it doesn't find cmds for the auto complete or any modules. When I write cmds. stuff like sphere come up, but they don't have the documentation. They should really make this easier to do. Thanks for your help btw
I added those lines, but when I type import maya. it doesn't find cmds for the auto complete or any modules. When I write cmds. stuff like sphere come up, but they don't have the documentation. They should really make this easier to do. Thanks for your help btw
I followed you instructions [using Maya 2018] and it was still not working for me. Found some video where the user removed "C:\Program Files\Autodesk\Maya2018\Python\Lib\site-packages" from the "Interpreter Paths" (your #4 step). Once I had done that it worked for me.
Thanks for the tip!
I followed you instructions [using Maya 2018] and it was still not working for me. Found some video where the user removed "C:\Program Files\Autodesk\Maya2018\Python\Lib\site-packages" from the "Interpreter Paths" (your #4 step). Once I had done that it worked for me.
Thanks for the tip!
it works! but i found a problem: Qt programs will no longer be able to run.
# simple example
import sys
from PySide2.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
label = QLabel("hello world!")
label.show()
sys.exit(app.exec_())
# get error
app = QApplication(sys.argv) TypeError: 'NoneType' object is not callable
it works! but i found a problem: Qt programs will no longer be able to run.
# simple example
import sys
from PySide2.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
label = QLabel("hello world!")
label.show()
sys.exit(app.exec_())
# get error
app = QApplication(sys.argv) TypeError: 'NoneType' object is not callable
For Maya 2018, PyCharm 2019.2, these instructions worked as described above.
1. Added the mayapy.exe interpreter
2. Edited the interpreter paths to remove the site-packages
What I found unnecessary were the suggested changes to any of the devkit source files (e.g. OpenMayaUI.py). In your script, just import API 2.0 as described in the docs:
For OpenMayaUI, you can do something like:
import maya.api.OpenMayaUI as omui
omui.MMaterial.getTextureTransformation()
This gets you autocompletion and the documentation.
The downside, is that you lose the ability to go to the source for pymel commands inside site-packages. For example, with this code:
import pymel.core as pm
pm.exportSelected()
when you right click on exportSelected() and choose Go To -> Declaration:
- With site-packages included, this goes to the source in: Autodesk\Maya2018\Python\Lib\site-packages\pymel\core
def exportSelected(exportPath, **kwargs):
_setTypeKwargFromExtension(exportPath, kwargs)
kwargs['exportSelected'] = True
res = cmds.file(exportPath, **kwargs)
if res is None:
res = exportPath
return Path(_correctPath(res))- Without site-packages, it goes to the docs in: devkitBase\devkit\other\pymel\extras\completion\py\pymel\core
def exportSelected(exportPath, **kwargs):
"""
Export the selected items into the specified file. Returns the name of the exported file.
Flags:
- force:
...
For Maya 2018, PyCharm 2019.2, these instructions worked as described above.
1. Added the mayapy.exe interpreter
2. Edited the interpreter paths to remove the site-packages
What I found unnecessary were the suggested changes to any of the devkit source files (e.g. OpenMayaUI.py). In your script, just import API 2.0 as described in the docs:
For OpenMayaUI, you can do something like:
import maya.api.OpenMayaUI as omui
omui.MMaterial.getTextureTransformation()
This gets you autocompletion and the documentation.
The downside, is that you lose the ability to go to the source for pymel commands inside site-packages. For example, with this code:
import pymel.core as pm
pm.exportSelected()
when you right click on exportSelected() and choose Go To -> Declaration:
- With site-packages included, this goes to the source in: Autodesk\Maya2018\Python\Lib\site-packages\pymel\core
def exportSelected(exportPath, **kwargs):
_setTypeKwargFromExtension(exportPath, kwargs)
kwargs['exportSelected'] = True
res = cmds.file(exportPath, **kwargs)
if res is None:
res = exportPath
return Path(_correctPath(res))- Without site-packages, it goes to the docs in: devkitBase\devkit\other\pymel\extras\completion\py\pymel\core
def exportSelected(exportPath, **kwargs):
"""
Export the selected items into the specified file. Returns the name of the exported file.
Flags:
- force:
...
Can't find what you're looking for? Ask the community or share your knowledge.