Compiling PyQt4 on Mac OS X 10.6 (Snow Leopard)

17 06 2011

So i recently started messing around with pyqt4 and python, and i wanted it to work on my mac, but to my dismay i had to compile it from source.

So, here is how i did it. You will need some things

You will probably need XCode so you get access to gcc and other things. You can get it from here: http://developer.apple.com/xcode/ (you either need to pay 5 dollars for xcode 4 or look for a link on that page saying “looking for xcode 3?” which is free.)

First, download and install the QT SDK here: http://qt.nokia.com/downloads I would put it somewhere in your home folder, I put it in ~/Programs/QtSDK

Now, you need to download the source tarballs (the Mac OSX / Linux ones) for PyQT4 and SIP (which is used to generate the python bindings for the c++ code in qt). Get them here:  http://www.riverbankcomputing.com/software/sip/download and http://www.riverbankcomputing.com/software/pyqt/download . I created a folder pyqtstuff to put the source tarballs in. Extract them both and you should have two folders for each of the tarballs.

You need to compile SIP first. Now Mac OSX has python 2.6 already installed, if you want to use python 3 you need to install that. Whatever version of python you want to use pyqt4 with, you NEED to run the following scripts with the version of python you want to use. So if you want to use 2.6, you just use ‘python configure.py’, if python 3, then ‘python3 configure.py .

So, change directories to the sp folder and then run these commands.

python configure.py

make

sudo make install

If all goes well, then it wont report any errors.

Now you change directories to the pyqt folder, and do the same thing, making sure to run the configure.py script as the version of python you are going to use with pyqt. BUT , i had a problem where it was saying that ‘qmake’ was not in my path. Never fear, thats why you downloaded the QT SDK. You need to locate the folder where you installed it, and deep inside it is the qmake binary. I installed the sdk to the QtSDK folder, and my qmake was in :

QtSDK/Desktop/Qt/473/gcc/bin/qmake

The version number will probably differ, but other then that the path is the same. Now, make sure you copy the FULL PATH (from root, so for me it would be  /Users/<username>/Programs/QtSDK/Desktop/Qt/473/gcc/bin/qmake , but substitute this with your own) and you need to pass it as an argument to the configure.py call. Again run this with the version of python you intend to use!

python configure.py -g -q <PATH TO QMAKE HERE>

That will configure pyqt. We use the -g because that ‘consolidates’ everything, which i’m not sure what that means, but the other option it told me to use did not work.

Now you just compile it and install it. This will probably take a bit of time since its kinda big. Be patient

make

sudo make install

Done! now you should be able to use PyQt4 on your mac. Hopefully this helps someone since I did not find a guide for it online yet. Post here if you have any questions!

About these ads

Actions

Information

7 responses

24 08 2011
Luis

Thank you SO MUCH! It’s amazing what you can find online.
I just installed Qt, and SIP and this is the help I needed.

17 09 2011
user@mail.com

great stuff, works! very helpful, thanks

30 10 2011
fee

SUPER !!

8 11 2011
dany

I spent two hours on this and then found your post and in 10 minutes resolved all, thanks!!!!

30 01 2012
Ben

Just a note that if you cannot use sudo, and you want to force 64-bit:

mkdir -p ~/bin ~/lib ~/share ~/include ~/Library/Python/2.6/site-packages

cd
python configure.py –arch=x86_64 -b ~/bin -d ~/Library/Python/2.6/site-packages -e ~/include -v ~/share
make
make install
cd
python configure.py –use-arch=x86_64 -g -q /Desktop/Qt//gcc/bin/qmake -b ~/bin -d ~/Library/Python/2.6/site-packages -e ~/include -v ~/share -e QtGui
make
make install
in your .profile / .bashrc etc:
export PYTHONPATH=$HOME/Library/Python/2.6/site-packages

I found I had to specify the module QtGui or it didn’t build, despite the docs saying that all modules are checked/built.

30 01 2012
Ben

(I had put sip-dir , pyqt-dir, qtsdk-dir, and qtsdk-version in less-than greater-than brackets which is why the cd’s show no directory, and why the path to the qtsdk qmake command is missing parts of the path. sorry! hopefully it is still decipherable)

2 05 2013
a four seater rhino

Its just like you read my head! You appear to know so much
applying this, because you wrote magic of creating up involved
or something which is. In my opinion that
you can employ some pics to drive your message home a bit, but as an alternative to that, it’s wonderful blog website.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: