Recent Posts

Categories

Maya and PyQt on OSX Snow Leopard and Hating It

So 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 most 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:

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.

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:

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:

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:

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:

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.

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: