«

»

Jan 07

Installing PyQt for maya 2011 (OSX)

Update:

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/Maya.app/Contents/bin/mayapy configure.py --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/Maya.app/Contents/bin/mayapy configure.py 
        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/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PyQt4 -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 sip
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())
form.show()

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/Maya.app/Contents/MacOS
sudo install_name_tool -change libQtCore.4.dylib @executable_path/QtCore 
    /Applications/Autodesk/maya2011/Maya.app/Contents/MacOS/libQtNetwork.4.dylib

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:

sys.path.insert(0,'/Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages')

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


References:

7 comments

Skip to comment form

  1. Aditya

    Hi,
    I had been having some other problem with qt & maya 2011.
    your info about copying libQtNetwork from the troltech dir to maya/lib did the trick
    thanks,
    aditya

  2. ArrantSquid

    I was just writing up some similar instructions because I couldn’t find any, only to stumble here and find this. So I’m glad the info is out there and I can stop. :) Just so you know, both your links are dead, however, if you go to http://distfiles.macports.org/python/ and search for both versions of PyQt and SIP you can get them from there. :) I had tried symlinking the installs from my site-packages to maya’s site-packages and using sys.path.append to add the folders from site-packages to Maya, but while it would “work” it would crash maya every time. I hate having dual installs of packages, but apparently Maya requires it. :/ Thanks again for the write up.

  3. Justin Israel

    @ArrantSquid: You are very welcome! And thanks for letting me know about the links. I just updated them.

  4. apostl3pol

    Great tute, thanks for posting this. It all worked well for me except that PyQt wouldn’t build. I finally figured out that copy-pasting the #4 “Build and Install” step into the terminal was giving me minuses and not dashes (or vice-versa), so it couldn’t find the paths. Typed those manually and everything went smoothly.

  5. Paul Jones

    hello,

    when i run the command from part 3

    ./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
    I’m presented with these choices.

    Type ‘c’ if you want to use the Commercial Edition.
    Type ‘o’ if you want to use the Open Source Edition.

    i Choose ‘o’ and get the following message:

    You don’t seem to have ‘make’ or ‘gmake’ in your PATH.
    Cannot proceed.

    i Do have the latest Xcode installed too.

    can you help

    many thanks
    Paul

  6. Izzy

    What Paul Jones said also happens to me :( Help?

  7. Nicolas

    I know this if off topic but I’m looking into starting my own blog and was curious what all is needed to get setup? I’m assuming having
    a blog like yours would cost a pretty penny? I’m not very internet smart so I’m not 100% certain.
    Any tips or advice would be greatly appreciated. Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>