Maya 2018 中没有名为 PyQt5.QtWidgets 的模块

No module named PyQt5.QtWidgets in Maya 2018

在 Maya 2018 中执行此代码时出现错误:

# Error: ImportError: file <maya console> line 3: No module named PyQt5.QtWidgets #

PyQt5 不是 Maya 2018 的一部分吗?

import maya.cmds as cmds
import sys 
from PyQt5.QtWidgets import (QWidget, QToolTip, QPushButton) 
from PyQt5.QtGui import QFont     

class Example(QWidget):
    def __init__(self):
        super(Example,self).__init__()
        self.initUI()

    def initUI(self):
        QToolTip.setFont(QFont('SansSerif', 10))
        self.setToolTip('This is a <b>QWidget</b> widget')
        btn = QPushButton('Button', self)
        btn.setToolTip('This is a <b>QPushButton</b> widget')
        btn.resize(btn.sizeHint())
        btn.move(50, 50) 
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Tooltips')
        self.show()

ex = Example() 

Qt 是 Maya 的一部分,但如果您想使用 PyQt5,则需要构建它。请注意,您需要针对 Qt 的 maya 修改版本构建它。

pyQt5 instruction for maya