Maya 2022 is shipped with Python 3.7 and Python 2.7 on Windows/Linux. Since Python 2 is no longer supported by the Python community, we encourge you to update to Python 3. This guide will only cover how to build and install PyQt5 for Maya 2022 with Python 3.
Although pip is shipped with Maya 2022, we can use it to install PyQt5 on Linux only. For Windows and Mac, we'll still need to build it manually.
When I am writing this guide, I am building with PyQt5-5.15.4.dev2103021428 and sip-6.0.3.dev2103021424. You can get them from Riverbank computing's website.
Windows:
We are going to build it with VS2019 which is same as Maya 2022's developing environment on Windows. If you've installed a path needs Administrator Privileges, please run x64 Native Tools Command Prompt for VS 2019 as Administrator. I've installed my Maya 2022 to default location and I've extracted devkit to g:\case\devkitBase\2022. Please update it with the paths on your computer. Here are the steps:
Subst your maya install folder to a dedicate drive if there is a space inside your maya installation path. I am going to subst it to drive v e.g.
subst v: "c:\program files\autodesk\maya2022"
Add your maya2022\Python37\scripts and maya2022\bin to your system path. If your've created a subst drive, please use the path with drive. e.g.
set path=%path%;v:\bin;v:\Python37\Scripts
Copy include\Python37\Python inside Maya2022 installation as Python37\include.
Copy lib\python37.lib inside Maya2022 installation to Python37\libs. You'll need to create the destination folder. Once you've copied the libarary, please duplicate one and name it as python3.lib.
Use mayapy to install packaging and toml. e.g.
mayapy -m pip install toml mayapy -m pip install packaging
Go to sip source folder. Use mayapy to install sip. e.g.
v:\bin\mayapy setup.py install
install PyQt-builder and PyQt5-sip with pip
mayapy -m pip install PyQt-builder mayapy -m pip install PyQt5-sip
Download devkit, unzip the mkspec in the mkspec folder directly into its directory. Unzip the Qt include files into the include directory directly. Rename include\qtnfc to qtnfc.disabled.
Update mkspecs/common/msvc-desktop.conf in the mkspecs, enable shell and add COM libraries to build config.
QMAKE_LIBS = ole32.lib OleAut32.lib QMAKE_LIBS_QT_ENTRY = -lqtmain -lshell32
Go to PyQt5 source folder. Use following command to install PyQt5. Please update the devkit path with the one on your computer.
sip-install --jobs 32 --no-designer-plugin --spec g:\case\devkitBase\2022\mkspecs\win32-msvc --qmake g:\case\devkitBase\2022\devkit\bin\qmake.exe --verbose
The jobs count shouldn't be more than the count of your logical processors. I am using a 5950x which has 32 logical processors so the jobs is 32 here. If you don't want debug output, please remove the --verbose flag in the end.
Vola, it works.
Mac:
If you are going to install it on MacOSX Catalina, please install the latest Xcode 11. As I am writing this guide, there will be warning when using Xcode 12 to build and install PyQt5. Since Xcode 12 is required by BigSur, please install it on MacOSX Catalina or Mojave if possible. I've installed Maya 2022 to default path and extract devkit and PyQt5 source codes into ~/Documents/pyqt5.2022/. Please update the path in the scripts if you are using a different location.
Download devkit, unzip the mkspec in the mkspec folder directly into its directory. Unzip the Qt include files into the include directory directly. Rename include\qtnfc to qtnfc.disabled.
Go to sip source code folder. Build and install sip. e.g.
sudo /Applications/Autodesk/Maya2022/Maya.app/Contents/bin/mayapy setup.py install
Use pip to install PyQt-builder and PyQt5-sip. e.g.
sudo /Applications/Autodesk/Maya2022/Maya.app/Contents/bin/mayapy -m pip install PyQt-builder sudo /Applications/Autodesk/Maya2022/Maya.app/Contents/bin/mayapy -m pip install PyQt5-sip
Use following script to build PyQt5. Please update the path with your Maya 2022 installation path.
#!/usr/bin/env bash export PYTHONHOME=/Applications/Autodesk/maya2022/Maya.app/Contents/Frameworks/Python.framework/Versions/Current export DYLD_LIBRARY_PATH=/Applications/Autodesk/maya2022/Maya.app/Contents/MacOS:$DYLD_LIBRARY_PATH export DYLD_FRAMEWORK_PATH=/Applications/Autodesk/maya2022/Maya.app/Contents/Frameworks:$DYLD_FRAMEWORK_PATH /Applications/Autodesk/Maya2022/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/bin/sip-install --jobs 16 --no-designer-plugin --spec ~/Documents/pyqt5.2022/devkit/mkspecs/macx-clang --qmake ~/Documents/pyqt5.2022/devkit/devkit/bin/qmake --verbose
Copy these scripts into a script file inside the directory of PyQt5 source files and execute it with sudo. If you can't execute it, please use chmod +x *filename * to make it executable.
Go to build folder, remove the install-distinfo from the install target in the Makefile, e.g.
install:install_subtargets install_uic install_init install_scripts install-distinfo FORCE
to
install:install_subtargets install_uic install_init install_scripts FORCE
Install the build first.
sudo make install
Use following script to execute install-distinfo target. Please update it with your local paths.
#!/usr/bin/env bash export PYTHONHOME=/Applications/Autodesk/maya2022/Maya.app/Contents/Frameworks/Python.framework/Versions/Current export DYLD_LIBRARY_PATH=/Applications/Autodesk/maya2022/Maya.app/Contents/MacOS:$DYLD_LIBRARY_PATH export DYLD_FRAMEWORK_PATH=/Applications/Autodesk/maya2022/Maya.app/Contents/Frameworks:$DYLD_FRAMEWORK_PATH /Applications/Autodesk/Maya2022/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/bin/sip-distinfo --inventory /Users/lichengxi/Documents/pyqt5.2022/PyQt5-5.15.4.dev2103021428/build/inventory.txt --project-root /Users/lichengxi/Documents/pyqt5.2022/PyQt5-5.15.4.dev2103021428 --prefix "" --generator sip-build --console-script pylupdate5=PyQt5.pylupdate_main:main --console-script pyrcc5=PyQt5.pyrcc_main:main --console-script pyuic5=PyQt5.uic.pyuic:main --requires-dist "PyQt5-sip (>=12.8, <13)" /Applications/Autodesk/maya2022/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.7/site-packages/PyQt5-5.15.4.dev2103021428.dist-info
Copy these scripts into a script file and execute it with sudo.
That's it.
Linux
You can use pip to install PyQt5. e.g. sudo mayapy -m pip install PyQt5
Test your installation
After install PyQt5, you can use following script to test your installation.
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()
If PyQt5 is properly installed, you will see a popup window with a button.
Comments
You can follow this conversation by subscribing to the comment feed for this post.