Written by Cyrille Fauvel – Autodesk Developer Network (April 2013)
Updated by Chengxi Li – Autodesk Developer Network (August 2018)
Building SIP, and PyQt for Maya 2018 PyQt [https://www.riverbankcomputing.co.uk] is a python binding to the Qt library. Because Maya uses Qt internally, you can use the PyQt modules in Maya python scripts to create custom UI. PyQt does not have the same licensing as Maya, Qt, or Python. Please consult the PyQt website for information about licensing for PyQt.
Download PyQt: https://www.riverbankcomputing.com/software/pyqt/download
Download SIP: https://www.riverbankcomputing.com/software/sip/download
The following are instructions for building a copy of the PyQt modules that have been known to work with Maya.
Maya 2018 uses Qt5.6.1 which is binary compatible with the latest version of PyQt – 5.9 / SIP – 4.19.2
Note that it’s important to use the Maya modified version of the Qt source code. A copy of the customized Qt 5.6.1 source is available from Autodesk’s Open Source web-site (https://www.autodesk.com/lgplsource) and includes text files describing how to configure, build and install Qt for each platform supported by Maya.
However, be aware that with Maya 2018, there is no more need to build PySide as it is coming by default in Maya, nor you have to rebuild Qt itself as the main Qt tools to build PyQt are now included in the Maya distributions (I.e. qmake, moc, …)
libxml, openSSL, OpenAL, python2.7, qt-5.6.1, and tbb are also coming by default in the Maya include and lib folders, so unless you have a very specific need, you would not need to rebuild any of those libraries like before. Note as well that there is a ‘MAYA_LOCATION/support/opensource’ folder now which contains some of the community source.
Important: Maya 2018 now ships without the devkit, include and mkspecs folders. You can get the Maya 2018 devkit from the Autodesk App Store here for Windows, OSX, and Linux. Download the devkit and unzip the files into your Maya root folder. Make sure to read the instructions to install the devkit, include and mkspecs folders properly on your system.
The scripts used in this document are now also posted on Github.
Download SIP and PyQt source from ‘https://www.riverbankcomputing.co.uk‘ – here I downloaded ‘sip- 4.19.3’ and ‘PyQt5_gpl-5.9’. Unzip them in one folder.
Mac
/Users/cyrille/Documents/_Maya2018Scripts/sip-4.19.3
/Users/cyrille/Documents/_Maya2018Scripts/PyQt5_gpl-5.9
/Users/cyrille/Documents/_Maya2018Scripts/ being my local folder.
Here are the instructions and scripts for building SIP and PyQt.
Follow the instructions from the API docs to setup your environment (Developer Resources > API Guide > Setting up your build environment > Mac OS X environment, in the Maya Documentation)
If you would like to use Xcode 7.3.1 to compile it and you are having multiple installation of Xcode. Please backup /Applications/Xcode.app and use Xcode 7.3.1 to replace it.
Use xcode-select to change active xcode like below:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
The qt.conf file uses MAYA_LOCATION and DEVKIT_LOCATION to locate the expected header/library files. Therefore, users must set both environment variables before building the PyQt5.
DEVKIT_LOCATION should point to the directory where the devkit include, mkspecs, cmake directories are located.
Modify devkit/bin/qt.conf as below:
[Paths]Prefix=Libraries=$(MAYA_LOCATION)/MacOSBinaries=$(DEVKIT_LOCATION)/devkit/binHeaders=$(DEVKIT_LOCATION)/include/QtArchData=$(DEVKIT_LOCATION)Data=$(DEVKIT_LOCATION)HostData=$(DEVKIT_LOCATION)HostBinaries=$(DEVKIT_LOCATION)/devkit/binHostLibraries=$(MAYA_LOCATION)/MacOS
Untar the include/qt-5.6.1-include.tar.gz into /include/Qt
Untar the qt-5.6.1-mkspecs.tar.gz into /Applications/Autodesk/maya2017/mkspecs. Make sure the qconfig.pri looks like this:
qconfig.pri
#configuration CONFIG += release def_files_disabled exceptions no_mocdepend stl x86_64 qt #qt_framework QT_ARCH = macosx QT_EDITION = OpenSource QT_CONFIG += minimal-config small-config medium-config large-config full-config no-pkg-config dwarf2 phonon phonon-backend accessibility opengl reduce_exports ipv6 getaddrinfo ipv6ifname getifaddrs png no-freetype system-zlib nis cups iconv openssl corewlan concurrent xmlpatterns multimedia audio-backend svg script scripttools declarative release x86_64 qt #qt_framework#versioning QT_VERSION = 5.6.1 QT_MAJOR_VERSION = 5 QT_MINOR_VERSION = 6 QT_PATCH_VERSION = 1#namespaces QT_LIBINFIX =QT_NAMESPACE = QT_NAMESPACE_MAC_CRC =
Build & Install SIP
Please use the script below, you can also find it in GitHub.
#!/usr/bin/env bash MAYAQTBUILD="`dirname "$0"`" # Relativeexport MAYAQTBUILD="`( cd "$MAYAQTBUILD" && pwd )`" # Absolutized and normalizedpushd $MAYAQTBUILD export SIPDIR=$MAYAQTBUILD/sip-4.19.3export MAYA_LOCATION=/Applications/Autodesk/maya2018 pushd $SIPDIR$MAYA_LOCATION/Maya.app/Contents/bin/mayapy ./configure.py --arch=x86_64makesudo make installpopdpopd
Build & Install PyQt
Please use the script below, you can also find it in GitHub.
#!/usr/bin/env bash MAYAQTBUILD="`dirname "$0"`" # Relativeexport MAYAQTBUILD="`( cd "$MAYAQTBUILD" && pwd )`" # Absolutized and normalizedpushd $MAYAQTBUILD export MAYA_LOCATION=/Applications/Autodesk/maya2018/Maya.app/Contentsexport DEVKIT_LOCATION=/Applications/Autodesk/maya2018export QTDIR=$DEVKIT_LOCATION/devkitexport QMAKESPEC=$DEVKIT_LOCATION/mkspecs/macx-clangexport INCDIR_QT=$DEVKIT_LOCATION/include/Qtexport LIBDIR_QT=$MAYA_LOCATION/MacOSerror=0if [ ! -f $QMAKESPEC/qmake.conf ];then echo "You need to install qt-5.6.1-mkspecs.tar.gz in $QTDIR/mkspecs !" error=1fiif [ ! -f $INCDIR_QT/QtCore/qdir.h ];then echo "You need to uncompress $MAYA_LOCATION/devkit/include/qt-5.6.1-include.tar.gz in $INCDIR_QT !" error=1fi# qt.conf - /Applications/Autodesk/maya2018/Maya.app/Contents/Resourcesif [ ! -f $QTDIR/bin/qt.conf ];then echo "You need to copy $QTDIR/Resources/qt.conf in $QTDIR/bin !" error=1fi test=`grep 'Data=$(DEVKIT_LOCATION)' $QTDIR/bin/qt.conf`if [ -z "$test" ];then echo "You need to edit $QTDIR/bin/qt.conf to use 'Data=$(DEVKIT_LOCATION)'" error=1fitest=`grep 'Headers=$(DEVKIT_LOCATION)/include/Qt' $QTDIR/bin/qt.conf`if [ -z "$test" ];then echo "You need to edit $QTDIR/bin/qt.conf to use 'Headers=$(DEVKIT_LOCATION)/include/Qt'" error=1fitest=`grep 'Libraries=$(MAYA_LOCATION)/MacOS' $QTDIR/bin/qt.conf`if [ -z "$test" ];then echo "You need to edit $QTDIR/bin/qt.conf to use 'Libraries=$(MAYA_LOCATION)/MacOS'" error=1fiif [ $error -eq 1 ];then exitfi export DYLD_LIBRARY_PATH=$MAYA_LOCATION/MacOSexport DYLD_FRAMEWORK_PATH=$MAYA_LOCATION/Frameworks export SIPDIR=$MAYAQTBUILD/sip-4.19.3export PYQTDIR=$MAYAQTBUILD/PyQt5_gpl-5.9 export SIP_EXE=$MAYA_LOCATION/Frameworks/Python.framework/Versions/2.7/bin/sipexport SIP_INCLUDE=$MAYA_LOCATION/Frameworks/Python.framework/Versions/2.7/include/python2.7pushd $PYQTDIRexport PATH=$QTDIR/bin:$PATHecho echo Environmentecho -----------setecho -----------echo QT Settingsecho -----------qmake -queryecho -----------echo$MAYA_LOCATION/bin/mayapy ./configure.py QMAKE_MAC_SDK=macosx10.11 QMAKE_RPATHDIR+=$LIBDIR_QT --sip=$SIP_EXE --sip-incdir=$SIP_INCLUDE -w --no-designer-plugin make -j 8sudo make installpopdpopd
Note that I am compiling against Mac OS X SDK 10.11 which is same as the developer environment. If you want to compile against other versions, please modify the script(macosx10.11).
You’re done! Please check the testing paragraph at the end of the article.
Linux
/home/cyrille/Documents/_Maya2018Scripts/sip-4.19.3
/home/cyrille/Documents/_Maya2018Scripts/PyQt5_gpl-5.9
/home/cyrille/Documents/_Maya2018Scripts being my local folder.
Here are the instructions and scripts for building SIP and PyQt.
Follow the instructions from the API docs to setup your environment (Developer Resources > API Guide > Setting up your build environment > Linux environments (64 bit), in the Maya Documentation).
The qt.conf file uses MAYA_LOCATION and DEVKIT_LOCATION to locate the expected header/library files. Therefore, users must set both environment variables before building the PyQt5.
DEVKIT_LOCATION should point to the directory where the devkit include, mkspecs, cmake directories are located.
Please backup your qt.conf first, you’ll need to restore it after building PyQt5. Replace …/bin/qt.conf with below:
[Paths] Prefix= Libraries=$(MAYA_LOCATION)/lib Binaries=$(DEVKIT_LOCATION)/binHeaders=$(DEVKIT_LOCATION)/include/Qt ArchData=$(DEVKIT_LOCATION) Data=$(DEVKIT_LOCATION) HostData=$(DEVKIT_LOCATION) HostBinaries=$(DEVKIT_LOCATION)/bin
Untar the /include/qt-5.6.1-include.tar.gz into /include/Qt
Untar the /mkspecs/qt-5.6.1-mkspecs.tar.gz into /mkspecs
Make qmake, moc executables from the Maya bin directory
sudo chmod aog+x /usr/autodesk/maya2018/bin/moc sudo chmod aog+x /usr/autodesk/maya2018/bin/qmake
Build & Install SIP
Please use the script below, you can also find it in GitHub.
#!/usr/bin/env bash MAYAQTBUILD="`dirname "$0"`" # Relativeexport MAYAQTBUILD="`( cd "$MAYAQTBUILD" && pwd )`" # Absolutized and normalizedpushd $MAYAQTBUILD export SIPDIR=$MAYAQTBUILD/sip-4.19.3export MAYA_LOCATION=/usr/autodesk/maya2018 pushd $SIPDIR$MAYA_LOCATION/bin/mayapy ./configure.pymakesudo make installpopdpopd
Build & Install PyQt
Please use the script below, you can also find it in GitHub.
#!/usr/bin/env bash MAYAQTBUILD="`dirname "$0"`" # Relativeexport MAYAQTBUILD="`( cd "$MAYAQTBUILD" && pwd )`" # Absolutized and normalizedpushd $MAYAQTBUILD export MAYA_LOCATION=/usr/autodesk/maya2017export QTDIR=$MAYA_LOCATIONexport DEVKIT_LOCATION=$MAYA_LOCATIONexport QMAKESPEC=$QTDIR/mkspecs/linux-g++-64export INCDIR_QT=$MAYA_LOCATION/include/Qtexport LIBDIR_QT=$QTDIR/liberror=0if [ ! -f $QMAKESPEC/qmake.conf ];then echo "You need to install qt-5.6.1-mkspecs.tar.gz in $QTDIR/mkspecs !" error=1fiif [ ! -f $INCDIR_QT/QtCore/qdir.h ];then echo "You need to uncompress $MAYA_LOCATION/include/qt-5.6.1-include.tar.gz in $INCDIR_QT !" error=1fi# qt.conf - $QTDIR/bin/qt.confif [ ! -f $QTDIR/bin/qt.conf ];then echo "You need to copy $QTDIR/Resources/qt.conf in $QTDIR/bin !" error=1fi# The grep string should be in single quote('), if it is in double quote (""), # shell will expand the variable, hence the intension of the below grep will fail test=`grep 'Headers=$(DEVKIT_LOCATION)/include/Qt' $QTDIR/bin/qt.conf`if [ -z "$test" ];then echo "You need to edit $QTDIR/bin/qt.conf to use 'Headers=$(DEVKIT_LOCATION)/include/Qt'" error=1fiif [ $error -eq 1 ];then exitfi export SIPDIR=$MAYAQTBUILD/sip-4.19.3export PYQTDIR=$MAYAQTBUILD/PyQt5_gpl-5.9 pushd $PYQTDIRexport PATH=$QTDIR/bin:$PATH$QTDIR/bin/mayapy ./configure.py LIBDIR_QT=$LIBDIR_QT INCDIR_QT=$INCDIR_QT MOC=$QTDIR/bin/moc -w --no-designer-plugin make -j 8sudo make installpopdpopd
You’re done! Please check the testing paragraph at the end of the article.
Windows
D:__sdkext_Maya2018 Scriptssip-4.19.3
D:__sdkext_Maya2018 ScriptsPyQt5_gpl-5.9
D:__sdkext_Maya2018 Scripts being my local folder.
Here are the instructions and scripts for building SIP and PyQt.
Follow the instructions from the API docs to setup your environment (Developer Resources > API Guide > Setting up your build environment > Windows environment (64-bit), in the Maya Documentation)
Please backup your qt.conf first, you’ll need to restore it after building PyQt5. Replace …/bin/qt.conf with below:
[Paths]Prefix=$(MAYA_LOCATION)Libraries=lib Binaries=bin Headers=include/QtData=.Plugins=qt-plugins Translations=qt-translations Qml2Imports=qml
Unzip the /include/qt-5.6.1-include.tar.gz into /include/Qt
Unzip the /mkspecs/qt-5.6.1-mkspecs.tar.gz into /mkspecs
Please run following build scripts with VS2012 x64 Native Tools Command Prompt. If your Maya installed in folders required administrator privilege(e.g. Program files), please run the command prompt as Administrator.
Environment Setup
@echo offset MAYAVERSION=2018set ADSKQTVERSION=5.6.1set SIPVERSION=4.19.3set PYQTVERSION=5.9set MAYADRIVE=m:set BUILDDRIVE=v:if exist %MAYADRIVE%nul subst %MAYADRIVE% /dsubst %MAYADRIVE% "C:Program FilesAutodeskMaya%MAYAVERSION%"set MAYA_LOCATION=%MAYADRIVE%set MAYAPYQTBUILD=%~dp0rem Removing trailing set MAYAPYQTBUILD=%MAYAPYQTBUILD:~0,-1%if exist %BUILDDRIVE%nul subst %BUILDDRIVE% /dsubst %BUILDDRIVE% "%MAYAPYQTBUILD%"set SIPDIR=%BUILDDRIVE%sip-%SIPVERSION%set PYQTDIR=%BUILDDRIVE%PyQt5_gpl-%PYQTVERSION%rem set ADSKQTDIR=%BUILDDRIVE%qt-%ADSKQTVERSION%set QTDIR=%MAYA_LOCATION%set PATH=%QTDIR%bin;%PATH%set MSVC_VERSION=2015set MSVC_DIR=C:Program Files (x86)Microsoft Visual Studio 14.0set QMAKESPEC=%QTDIR%mkspecswin32-msvc%MSVC_VERSION%set _QMAKESPEC_=win32-msvc%MSVC_VERSION%if ["%LIBPATH%"]==[""] call "%MSVC_DIR%VCvcvarsall" amd64set INCLUDE=%INCLUDE%;%MAYA_LOCATION%includepython2.7set LIB=%LIB%;%MAYA_LOCATION%lib
Build & Install SIP
Please use the script below, you can also find it in GitHub.
@echo offset XXX=%~dp0if ["%MAYAPYQTBUILD%"]==[""] call "%XXX%setup.bat"pushd %SIPDIR%rem "%MAYA_LOCATION%binmayapy" configure-ng.py --spec %_QMAKESPEC_%"%MAYA_LOCATION%binmayapy" configure.pynmakenmake installpopd
Build & Install PyQt
Please use the script below, you can also find it in GitHub.
@echo offset XXX=%~dp0if ["%MAYAPYQTBUILD%"]==[""] call "%XXX%setup.bat"set QMAKESPEC=%QTDIR%mkspecs%_QMAKESPEC_%if not exist "%QMAKESPEC%qmake.conf" ( echo "You need to uncompress %MAYA_LOCATION%mkspecsqt-5.6.1-mkspecs.tar.gz !" goto end)if not exist "%MAYA_LOCATION%includeQtQtCoreqdir.h" ( echo "You need to uncompress %MAYA_LOCATION%includeqt-5.6.1-include.tar.gz in %MAYA_LOCATION%includeQt !" goto end)findstr /L /C:"Headers=include/Qt" "%MAYA_LOCATION%binqt.conf" >nul 2>&1if ERRORLEVEL 1 ( echo "You need to edit %MAYA_LOCATION%binqt.conf to use 'Headers=include/Qt'" goto end)findstr /L /C:"-lqtmain -lshell32" "%QTDIR%mkspecscommonmsvc-desktop.conf" >nul 2>&1if ERRORLEVEL 1 ( echo "You need to edit %QTDIR%mkspecscommonmsvc-desktop.conf to use 'QMAKE_LIBS_QT_ENTRY = -lqtmain -lshell32'" goto end)if not exist "%MAYA_LOCATION%includeQtqtnfc.disabled" ( echo "You need to rename %MAYA_LOCATION%includeQtqtnfc to %MAYA_LOCATIONincludeQtqtnfc.disabled" goto end) pushd %PYQTDIR%"%MAYA_LOCATION%binmayapy" configure.py --spec %QMAKESPEC% LIBDIR_QT="%QTDIR%lib" INCDIR_QT="%QTDIR%includeQt" MOC="%QTDIR%binmoc.exe" --sip="%QTDIR%Pythonsip.exe" --sip-incdir="%QTDIR%Pythoninclude" -w --no-designer-pluginnmakenmake installpopd:end
You’re done! Please check the testing paragraph at the end of the article.
Testing
Copy and paste this example in the Maya Script Editor (in a Python tab), and execute the code:
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 you see the dialog showing, you are all set.

Leave a Reply