Sunday, January 17, 2010

Building PyQt4 on Snow Leopard

Here are some notes on building PyQt4 on OSX 10.6 as I always seem to miss a step every time I do this! It should be very similar for all POSIX systems except for a few flags here and there.

My set up: Intel MacBook Pro, OSX 10.6.2, Python 2.6.1 (Apple system python 64-bit, not python.org 32-bit Python).

Get Qt LGPL package. Note, you want the Qt Cocoa libraries as PyQt4 expects 64 bit libraries. The default libraries in the Qt SDK are for Carbon (32-bit) for backwards compatibility. Snow Leopard gcc compiles 64-bit code by default.
Get latest sip. Build and install:
  • python configure.py
  • Check configuration is what you want.
  • make
  • sudo make install
Get QScintilla package from Riverbank.
  • cd Qt4
  • qmake -spec macx-g++ qscintilla.pro
  • make
  • sudo make install
  • make clean
Now get Mac PyQt4 from Riverbank:
  • python configure.py
  • Accept the GPL license.
  • Check the configuration log doesn't contain anything silly.
  • make
  • Go and make a cup of tea. You have plenty of time.
  • sudo make install
  • Test to see if there: python -c 'import PyQt4; print PyQt4'
If you get some error about PyQt4 being 64-bit and Qt is 32 bit, you've installed (or built) the default Carbon version of Qt. Build or install the 64 bit Cocoa version, as instructed above.

Now, back to QScintilla package as we're going to build the Python bindings. This has to be done after PyQt has been built and installed.
  • cd Python
  • python configure.py
  • make
  • sudo make install
  • make clean
Now the Qt Designer QScintilla plug-in:
  • cd designer-Qt4
  • qmake -spec macx-g++
  • make
  • sudo make install
  • make clean
  • Start Designer and make sure the QScintilla plug-in is there.

10 comments:

Jon said...

Hi,
I'm trying to follow your directions with the same OSX 10.6.2 and Python 2.6.1, but when I try to build PyQt, it bombs out of the Makefile with the following error:

./pyrcc4 -py2 -o ../examples/activeqt/webbrowser/._mainwindow_rc.py ../examples/activeqt/webbrowser/._mainwindow.qrc
pyrcc4 Parse Error:../examples/activeqt/webbrowser/._mainwindow.qrc:1:1 [error occurred while parsing element]

Any suggestions? (Thanks, btw, for writing such a clear explanation of the build procedure -- it's been quite helpful so far, up to the point I'm stuck at :-)

-Jon

Jon said...

Hmm, I got it to build by commenting out all the lines in the Makefile that were trying to invoke pyrcc4 on AppleDouble encoded files and it built libqscintillaplugin.dylib, but it shows up in Designer in the "Failed Plugins" listing. :-(

MoaningMarmot said...

Alternatively use http://github.com/mxcl/homebrew

Build from scratch Qt and PyQt4, no worries, dependencies are automatically handled

Chin Billy said...

Sorry Jon, been very busy. I think I may have added pyrcc to my path, hence mine works. When I upgrade to 4.6.2 I'll update the instructions.

MySchizoBuddy said...

minimum requirement for PyQwt is Python 2.6.2 and snow leopard comes with 2.6.1. What other option is there to get a 64bit version of Python 2.6.2

Chin Billy said...

@MySchizoBuddy: Not sure what you can do about that. The python.org page says that the "overwhelming recommendation of the 'MacPython' community is to upgrade your Python by downloading and installing a newer version from the Python standard release page."

It is odd that Apple don't upgrade Python when patching the OS. They used to upgrade Java, so why not Python? python.org distro of 2.6 is now 2.6.6.

I don't really want to have multiple versions of Python installed. I guess the version that is supplied with the OS is just a default trial version.

Fred said...

For PyQT configure.py part, I get:

Generating the C++ source for the QtCore module...
sh: /Users/apy/tmp/env27/bin/../bin/sip: No such file or directory

I am lost :-)

Chin Billy said...

@Fred: You need to build and install sip correctly in order to configure and compile PyQt. You may not have followed the instructions properly.

If you are having trouble then an alternative is to try installing the macports version. (I haven't tried this): http://www.macports.org/ports.php?by=name&substr=pyqt

Fred said...

Hi Chin Billy,

Yes, you are right - I had the 32bit Python version. Installed the 64bit. Went through all the steps and no problem. However I cannot see the QScintilla plug-in in Designer...

Should I re-do some steps?

Many thanks!
Fred

Brian said...

I just worked through this myself on 10.6.7. What a huge pain!

First I installed Python 2.7.1 from the official release page.

Then grab the Qt SDK 32/64 bit from the Qt.Nokia site.

Then I tried installing PyQt using MacPorts - and it decided as part of the dependency chain to install Python 2.4 in addition to the other 2 versions I already had. This cause numerous problems down the line.

Then I tried just building everything from various sources, and ran into a goofy hiccup building libpng.

Then I tried easy_install and/or PIP, encountering different errors.

What finally ended up working for me was starting with a clean slate (remove all Python, .eggs from easy_install and pip, etc...), and just install PyQt using homebrew. Then install PIP and install PyQt from there - no problems, finally.