Qt.py setup in Maya/PyCharm - Noob Question - Please help

qt

#1

Hello, i am learning python for Maya, trying to follow few tutorials and use Qt.py,
but i don’t think i was able to set up everything correctly… please help.

Maya 2016
PyCharm 2018.1.4 Community Edition

So, i downloaded Qt.py from https://github.com/mottosso/Qt.py
I placed it inside Maya scripts folder and it seems like everything works fine within Maya.
if i do something like:

import Qt
from Qt import QtWidgets
from Qt import QtGui
from Qt import QtCore
print Qt
print QtWidgets
print QtGui
print QtCore

win = Qt.QtWidgets.QDialog()
win.show()

This gives me:
<module ‘Qt’ from ‘C:/Users/My_Name/Documents/maya/2016/prefs/scripts\Qt.py’>
<module ‘Qt.QtWidgets’ (built-in)>
<module ‘Qt.QtGui’ (built-in)>
<module ‘Qt.QtCore’ (built-in)>

It creates an empty window, which makes we feel that everything is working correctly.

But when i put same code inside PyCharm
it says that it can’t find the reference

I have added my Maya scripts folder as a Source root
and I have selected Add source roots to PYTHONPATH
not sure what am i doing wrong, any hint would be much appreciated, thanks!


#2

@marcuso probably has more experience explaining this, and I’m not a PyCharm user, so the following is just a well informed guess.

But my guess is that because of the way that Qt.py dynamically creates its namespaces and modules, that PyCharm isn’t able to properly generate stubs / skeletons from it on the fly.

I believe there is an option for PyCharm to generate skeletons / stubs from the files it finds on the environment’s PYTHONPATH and that might work with Qt.py.


#3

Also not a PyCharm user, but there’s a discussion and what looks like workarounds for it here:


#4

Thank you @R.White!

Thank you @marcuso!

Copied QT stubs folder from https://github.com/fredrikaverpil/Qt.py/tree/stubs to my Maya scripts folder.
It resolved the issue!


#5

You need to add the Qt library package to your interpreter in the preferences. So you will have to PIP install PySide, PySide2, PyQt4, PyQt5 or whichever Qt library you are using because PySide won’t be linked to the modified Qt libraries that Maya Python uses.