Installing PyQt for maya 2011 (OSX)


I am now hosting a built package for Maya2011: MyQt4.7.4-maya2011-x64-osx-10.6.pkg And for Maya 2012+, see: Installing pyqt4 for maya2012

Personally, when trying to run PyQt from within Maya 2009 / 2010 using the pumpThread method, I never had much luck. The best I ever got was the ability to bring up a dialog but not without locking up the UI, even though the pumpThread tool is meant to address that.

Anyways, when I found out Maya 2011 was rewritten based on Qt for the UI, I was really stoked. I saw the example video of being able to design a ui file in Designer, and just directly open it in a maya script, and all I could think about was designing Qt GUIs so much more easily now. Turns out that Maya 2011 didn’t actually ship with PyQt included for licensing reasons I’m sure. But it included documentation on how one could go about building PyQt for maya. Unfortunately I had tons of issues that caused maya to just crash when importing PyQt.

What I finally figured out was a mish-mash of information from the maya documention, and different forums and user groups. So I decided to make this easier on anyone having the same problems as I did, and just collect that information into one place. This process is for OSX. I’m sure most of it is probably still relevant to linux or win, except for the last parts with ‘install_name_tool’. You would just need to make sure to find the right Qt/PyQt/SIP packages for your OS.

Building PyQt4 for Maya 2011 on OSX

Update for Maya 2012

While Maya uses newer versions, it seems the versions from the 2011 install still work. But here they are anyways incase you want the newer version for 2012:

Make sure you have downloaded and installed the latest XCode from Apple. Its also included on your OSX installation disc.

Qt: Maya has a specific version of Qt built into it. This is Qt 4.5.3.
  1. Download:  qt-mac-opensource-src-4.5.3.tar.gz
  2. Extract: tar zxvf qt-mac-opensource-src-4.5.3.tar.gz cd qt-mac-opensource-src-4.5.3

  3. Build and install: ./configure -cocoa -arch x86_64 -debug-and-release \ -no-phonon -no-phonon-backend -no-qt3support \ -no-webkit -nomake docs -nomake examples -nomake demos \ -nomake translations -no-rpath -no-framework make -j 8 sudo make install

SIP: The maya docs recommend sip version 4.10
  1. Download this specific SIP:   sip-4.10.tar.gz
  2. Extract:

    tar zxvf sip-4.10.tar.gz
    cd sip-4.10

  3. Build and install: /Applications/Autodesk/maya2011/ \ --arch=x86_64 make -j 8 sudo make install

PyQt4: The maya docs suggest PyQt 4.7
  1. Download this specific PyQt: PyQt-mac-gpl-4.7.4.tar.gz
  2. Extract:

    tar zxvf PyQt-mac-gpl-4.7.3.tar.gz
    cd PyQt-mac-gpl-4.7.3

  3. Set up some environment variables before building: export QTDIR=/usr/local/Trolltech/Qt-4.5.3 export PATH=/usr/local/Trolltech/Qt-4.5.3/bin:$PATH export QMAKESPEC=/usr/local/Trolltech/Qt-4.5.3/mkspecs/macx-g++ export DYLD_LIBRARY_PATH=/usr/local/Trolltech/Qt-4.5.3/lib

  4. Build and install: /Applications/Autodesk/maya2011/ \ \ LIBDIR_QT=/usr/local/Trolltech/Qt‐4.5.3/lib \ INCDIR_QT=/usr/local/Trolltech/Qt‐4.5.3/include \ MOC=/usr/local/Trolltech/Qt‐4.5.3/bin/moc \ -w --no-designer-plugin make -j 8 sudo make install

  5. PyQt4 will now be installed into Maya’s python site-packages, BUT will be linked against the wrong Qt binaries. The maya docs have an annoying multi step set of commands but they don’t copy/paste nicely, so here is a for-loop you can use: for mod in Core Gui Svg OpenGL Xml do sudo find /Applications/Autodesk/maya2011/ -name "*so" \ -exec install_name_tool -change libQt${mod}.4.dylib @executable_path/Qt${mod} {} ; done

At this point you should be able to start up Maya and import and run PyQt from the script editor. You no longer need the pumpThread. Here is a test code snippet that I borrowed from here (the original had typos in it that I corrected)

import maya.OpenMayaUI as mui from PyQt4.QtCore import * from PyQt4.QtGui import * def getMayaWindow(): ptr = mui.MQtUtil.mainWindow() return sip.wrapinstance(long(ptr), QObject) class Form(QDialog): def __init__(self, parent=None): super(Form, self).__init__(parent) self.setWindowTitle('Test Dialog') self.setObjectName('mainUI') self.mainLayout = QVBoxLayout(self) self.myButton = QPushButton('myButton') self.mainLayout.addWidget(self.myButton) global app global form app = qApp form = Form(getMayaWindow())

It doesn’t seem like you even need the install of Qt 4.5.3 that we did at this point since we changed the links, unless you use another Qt module besides QtCore, QtGui, QtSvg, QtXml, QtOpenGL (such as QtNetwork), but this could be solved by copying over the missing libs to where Maya is expecting them. Example for copying over QtNetwork:

sudo cp /usr/local/Trolltech/Qt-4.5.3/lib/libQtNetwork.* /Applications/Autodesk/maya2011/ sudo install_name_tool -change libQtCore.4.dylib @executable_path/QtCore /Applications/Autodesk/maya2011/

If you happen to have a mixed library environment like me, with more than one python lib location for code, and you see any funny errors while importing a module, just make sure that mayas python site-package is always in the front of the sys.path:


And there you have it. PyQt4 now installed in Maya 2011 under OSX.