This site will be undergoing dramatic maintenance, mostly because I hate php and don't want to continue to support the hybrid php/python implementation I have running, so be forewarned that the site (which has extremely low traffic since I'm not allowed to post anything fun anymore) may be down from time to time over the next week or two. (Sep 15, 2013)

mayor
 

import awesomeness as awsm

 

awsm.get_fortune('random')

The world is not octal despite DEC.

 

awsm.get_post_content('Maya and PyQt on OSX Snow Leopard and Hating It')

Posted at: July 12th, 2011 by: John Neumann

Maya PyQt OSXSo this post has been sitting in my queue for over 2 months now. Why? Well, because it was a lot of trial and error and a lot of failure. I happen to like having clean installs and refuse to have redundancy when I can avoid it. So I thought that I’d do an install of PyQt for OSX to the default Python and symlink it to Maya that way I only have one install that I have to update when I need to update it – among other reasons. Unfortunately, Maya hates that idea. Loathes it even. The errors it spits out are ugly and are basically kill errors that make it so you can’t use PyQt either from bash or from Maya. Loads of fun, eh? ;) To top it off, even if you do get PyQt to work with Maya, there’s no point – in my opinion – in putting PyQt into your default Python install so you can run it from the CLI. Why? Because this bug from ’09 still hasn’t been resolved and you’ll get the following error: “Qt internal error: qt_menu.nib could not be loaded.” Note that the bug I reference is actually for when you choose no-framework, however, even without choosing no-framework as a compile option you’ll still get that error. PyQt on OSX is like trying to set environment variables permanently in XP with a .bat file (pre-SP2 and without using the registry). There is hope though and after a little read on why I’m doing this, we’ll get there.

So I’ve been getting around to doing a few things with QT Designer and Python and I found out lots of fun and not-so-fun things. First, it’s almost impossible to use a straight QT Designer .ui file in Maya with Python without using PyQt. Why is this? Well, because you import the .ui file, but Maya doesn’t seem to have a way to understand which commands should be sent to the ui window. While in reality, this makes sense, I still find it idiotic. As I said earlier, there’s hope. You can use the nice QT windows you created in QT Designer, but it’s going to take some work (especially if you’re on OSX). Windows users, you’ve got it easy because Riverbank actually gives you pre-compiled binaries, so all you need to do is download Python and PyQt; Install both and you’re pretty much done. There’ll be some things you may need to do to get it working in Maya, but nothing more than just doing a sys.path.append in your userSetup.py file. Matter of fact, if you want a whole walkthrough on the whole #! (HA! That was nerdy.) go check out Christian Akesson’s blog post with the whole setup with Eclipse included.

Onto the OSX folks who are usually left out in the wind. :) Before I start, I want you to know three things: 1) I’m going to explain the things that didn’t work at the end, because I feel like it’s worth noting what I have tried; 2) In the end you will have a working install for Maya; and 3) I got some of my information to get a fully working version from Justin Israel’s site, so big ups to him for that. I’m going to assume you’re using the stock version of Python that came with OSX. If you’re not, you’ll have to modify some of the commands (which I’m not going to go into). If you have MacPorts or Fink installed, you’ll need to uninstall them, because this will fail with it installed. I know. I tried. Not sure if Homebrew users are ok, but I imagine you are since it doesn’t have extra headers for stuff. Also, if you’re unsure of what versions of Python you have installed you can open up a terminal and type:

file `which python` # those are backticks

And to check the architecture you’re running open up python in the terminal and type:

import sys
print(sys.maxsize)

Which will return either: 2147483647 (32bit) or 9223372036854775807 (64bit) – You could use import platform; platform.architecture() however, it returns 64bit whether you’re running 32 or 64 bit and is a known bug for OSX. Plus maxsize is actually a better way to determine it.

If you wish to switch your interpreter from 64 to 32 (or vice-versa, by switching yes to no), type this in the terminal:

export VERSIONER_PYTHON_PREFER_32_BIT=yes

(Do this because you’ll need these no matter what.) First you’re gonna need to download three things: QT 4.5.3; SIP 4.10; and PyQt 4.7.3. Throw them somewhere you’ll remember. I put them in my codingLibraries folder under my home directory. You can use curl to grab them like so:

curl -C - -LO http://distfiles.macports.org/python/sip-4.10.tar.gz
curl -C - -LO http://distfiles.macports.org/qt4-mac/qt-mac-opensource-src-4.5.3.tar.gz
curl -C - -LO http://distfiles.macports.org/python/PyQt-mac-gpl-4.7.3.tar.gz

Alright, now open up the terminal and we’re gonna install QT 4.5.3 first. Type the following:

cd ~/path/to/directory/of/files
tar -zxvf qt-mac-opensource-src-4.5.3.tar.gz
cd qt-mac-opensource-src-4.5.3 
make confclean # if you get this - make: *** No rule to make target `confclean'.  Stop. - it's fine
./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 -opensource
make -j 8 # read below before doing this
sudo make install

If you haven’t showered yet, now’s a good time. Grab some coffee, walk the dog, walk the parapet, watch a cartoon, but go do something because this can (and most likely will) take a while. Mine took a little over an hour on my Macbook Pro. YMMV. Alright, you’re back. Now we’ll install SIP.

cd ..
tar -zxvf sip-4.10.tar.gz
cd sip-4.10
/Applications/Autodesk/maya2011/Maya.app/Contents/bin/mayapy configure.py --arch=x86_64
make -j 8
sudo make install

SIP is now installed. Yay! Now cd back to your base directory with the files (cd ..)and let’s install PyQt.

cd ..
tar -zxvf PyQt-mac-gpl-4.7.3.tar.gz
cd PyQt-mac-gpl-4.7.3
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
/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 --confirm-license
make -j 8 # a quick walk of the dog or coffee this time
sudo make install

Lastly, you’ll need to run this command (which Justin Israel wrote, which is way more elegant than the way the doc’s tell you to do it):

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

And now you’re setup to use PyQt on OSX! At this point you should really jump over to that blog I pointed out to the Windows users earlier by Christian Akesson and setup Eclipse in all its goodness.

If you want to you can install QScintilla as well, which will give you access to the Eric IDE if you want to run that (I was a fan of SciTE when I had a working Linux box – before the hardware crash of ’09 :( ). This isn’t a necessary lib for PyQt, so you can skip it if you want. If not, cd back to your base directory with the files and let’s do it:

cd ..
curl -C - -LO http://www.riverbankcomputing.co.uk/static/Downloads/QScintilla2/QScintilla-gpl-2.5.1.tar.gz
tar -zxvf QScintilla-gpl-2.5.1.tar.gz
cd QScintilla-gpl-2.5.1
cd Qt4
qmake qscintilla.pro -spec macx-g++
make -j 8
sudo make install
cd ../python
python configure.py
make -j 8
sudo make install

So now you’ve got a working version of PyQt that will work with Maya. But what about from an interactive Python shell? Well 2 things should jump out at you already: 1) We compiled off of Maya’s Python; and 2) I already said there was a bug that kills PyQt from the CLI already. So what can we do? Well we can use Maya’s Python interpreter from the CLI and still get all the usefulness from PyQt without a redundant install. Just use:

/Applications/Autodesk/maya2011/Maya.app/Contents/bin/mayapy

And you can test it out with this – which I got from here.

import sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)

widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('simple')
widget.show()

sys.exit(app.exec_())

Yay! It works! Except that it’s kinda crappy that you’ve got to call Maya’s Python interpreter. Why is it crappy? Well I do lots of different development with Python (not just Maya) and I use libraries like Numpy which are installed to my default Python site-packages folder. So what can we do? Well, you can’t symlink the files to the site-packages directory. I tried that multiple times with different libraries and it won’t work. So you’re left with using sys.path.append when you want to use an external library from within Maya’s interpreter:

import sys
sys.path.append('/Library/Python/2.6/site-packages/numpy-2.0.0.dev_f72c605_20110113-py2.6-macosx-10.6-universal.egg')
import numpy as nmp

Definitely not ideal, but it does work. We can even make the process of calling Maya’s interpreter easier by adding this to our .bash_profile (or .profile if you use that instead):

# Set PATH for Maya 2011
PATH=$PATH:/Applications/Autodesk/maya2011/Maya.app/Contents/bin
PATH=$PATH:/Applications/Autodesk/maya2011/Maya.app/Contents/MacOS
export PATH

Now we can just do this to run scripts:

mayapy ~/myScripts/apythonscript.py

So that’s that! You can now run PyQt scripts from the CLI and while it’s not gorgeous or elegant, it does work.

Now I’m going to elaborate on what I tried previously to get Maya to work without having an extra lib installed. If you’ve already gleaned enough information, see ya. If you’re still interested, keep reading.

Instead of writing it all out, and boring you with details on what I tried at each step (and there were quite a few) here’s my bash code:

# QT
tar -zxvf qt-mac-opensource-src-4.5.3.tar.gz
cd qt-mac-opensource-src-4.5.3 
make confclean
./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 -opensource # omitted no-framework
make -j 8
sudo make install

# SIP
python configure.py --arch=x86_64
make -j 8
sudo make install

sudo ln -s /Library/Python/2.6/site-packages/sip.so /Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/sip.so

sudo ln -s /Library/Python/2.6/site-packages/sipconfig.py /Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/sipconfig.py

sudo ln -s /Library/Python/2.6/site-packages/sipdistutils.py /Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/sipdistutils.py

# PyQt
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

python 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 --confirm-license
make -j 8
sudo make install

sudo ln -s /Library/Python/2.6/site-packages/PyQt4/ /Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PyQt4

cd /Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/PyQt4


sudo find . -name "*so" -exec install_name_tool -change libQtCore.4.dylib @executable_path/QtCore {} \;
sudo find . -name "*so" -exec install_name_tool -change libQtCore.4.dylib @executable_path/QtGui {} \;
sudo find . -name "*so" -exec install_name_tool -change libQtCore.4.dylib @executable_path/QtSvg {} \;
sudo find . -name "*so" -exec install_name_tool -change libQtCore.4.dylib @executable_path/QtOpenGL {} \;
sudo find . -name "*so" -exec install_name_tool -change libQtCore.4.dylib @executable_path/QtXml {} \;

As you can see from that, I’m basically installing it all directly to my stock Python and then symlinking it to Maya’s site-packages (which as we already discussed, won’t work). I also attempted to omit the ‘no-framework’ option for QT so that I wouldn’t get that error regarding the qt_menu.nib file from the CLI. The problem is that it constantly failed when attempting to compile the networking components for some reason. You’ll also notice that I set the proper QT variables for Maya in the dumb way, whereas Justin’s way was much more elegant. I won’t post the error messages I received (unless someone is really that interested), but suffice it to say that when I was symlinking it to Maya, I couldn’t get it to work from the CLI nor Maya so it was rather useless.

So that’s that. Actually, for those of you who kept reading, here’s the entirety of the working script so that you can just save it as a bash script, set it to executable and walk away (kind of). You’ll need to confirm the license for the QT install and you’re going to need to provide your password (or the root password rather) to do sudo make install. Alternatively, you could take the sudo commands out of the file and run the entire script as root. I however, would only advise that if you really trust and like me. I’m not gonna screw with your machine and you should read the script before executing it – and I’m not liable for it either – but I don’t run most anything from anyone I don’t absolutely trust with sudo rights. Anyhow, here it is.

#!/bin/bash

# create a directory to download the files to
mkdir ~/tempLibs
cd ~/tempLibs

# download the files we need
curl -C - -LO http://distfiles.macports.org/python/sip-4.10.tar.gz
curl -C - -LO http://distfiles.macports.org/qt4-mac/qt-mac-opensource-src-4.5.3.tar.gz
curl -C - -LO http://distfiles.macports.org/python/PyQt-mac-gpl-4.7.3.tar.gz

# untar and compile qt
tar -zxvf qt-mac-opensource-src-4.5.3.tar.gz
cd qt-mac-opensource-src-4.5.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 -opensource
make -j 8
sudo make install

# untar and compile sip
cd ..
tar -zxvf sip-4.10.tar.gz
cd sip-4.10
/Applications/Autodesk/maya2011/Maya.app/Contents/bin/mayapy configure.py --arch=x86_64
make -j 8
sudo make install

# untar and compile pyqt
cd ..
tar -zxvf PyQt-mac-gpl-4.7.3.tar.gz
cd PyQt-mac-gpl-4.7.3
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
/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 --confirm-license
make -j 8
sudo make install

# link the binaries correctly
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

# delete our tempFile directory
cd ~/
rm -rf ~/tempLibs

# done
exit

Hope this helps some folks out and again, thanks to Justin for posting what he did because his info helped me get over that last hurdle – and everyone else who I’ve gathered information from on about this from the many websites I grep’d through.

Well that’s that! Hope this helps someone else out and hopefully it’ll save some folks some headaches. Till next time! :bloody:

Posted in Knowledge, Maya, Python Scripts, Tutorials | You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Maya and PyQt on OSX Snow Leopard and Hating It”

  1. [...] Maya and PyQt on OSX Snow Leopard and Hating It [...]

Leave a Reply

:p 8) :lol: =( :8 ;) :(( :o: :[ :) :D :-| :-[) :bloody: :cool: :choler: :love: :oups: :aie: :beurk:

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.