HomeContact
Computerz
installing PyQT4 on Mac OSX
René Dohmen
November 05, 2011
2 min

For a couple of our projects we used python with the Qt bindings to create a nice GUI.

In our normal mac osx dev environment I installed al Qt stuff with homebrew:

This has one problem; it uses the stock python; which is modified by apple.

Specifically, you cannot build standalone application bundles with the system python in OS X using py2app. I still don’t know how we deploy our app, so I will install py2app and pyinstaller later on and test both solutions with a mini pyqt hello world app.

Installing python + pyQt4

So on a clean mac i installed brew with this command:

Then I installed python

To make sure the brew installed python will be used I modified my ~/.profile

I started a new Terminal session, to make sure the new profile is used. At this moment you should have a working non stock python on your mac.

Et voila; you should have a working python2.7.2 with PyQt4.

To test it:

Install pyinstaller

Then you need the latest pyinstaller, make sure it’s fresh-> 64 bit support is still experimental. So I downloaded the hourly SVN trunk pyinstaller version and unzipped it to my home folder.

I also needed to install some extra python deps:

http://pypi.python.org/pypi/altgraph/#downloads

http://pypi.python.org/pypi/macholib#downloads

http://pypi.python.org/pypi/modulegraph/#downloads

For 64Bit Mac OSX you have to build the pyinstaller bootloader yourself.

Go to the source folder inside pyinstaller and execute:

You should have a working pyinstaller now. On my test mac it produces a .app which works.

I issued this commands:

After copying my qt_menu.nib with:

I had a working app, so brilliant stuff from the pyinstaller gurus

image0
image0
image1
image1

The only, problem at first: this app doesn’t get focus on launch.

You can fix it in your own code by adding

form.raise() right after

form.show() with “form” being whatever you called your instance of MainWindow().

I’ll have to test that still. But another more serious problem appeared when I transferred the app to another mac.

After some mails and a ticket in the pyinstaller ticket system, they fixed the problem in svn trunk r1740. The app now works on a clean OSX 10.6 en 10.7.

Install py2app

because the pyinstaller method uses experimental stuff and I like to have a plan B, I installed py2app also:

To install or upgrade to the latest released version of py2app:

Py2app behaves a little bit different. For starters it builds the app inside your project. It didn’t find my Qt install at first so I added on extra line to the code.

Then from inside my project I did:

Before you can build it you have to edit the generated setup.py file and set argv_emulation to False. Then it should be ready for the build.

That delivered a correct working app but I had to use pysinstaller svn trunk r1740 to get a working app thats runs on OS X 10.6 en OS X 10.7.

Code

In case anyone is interested in the Code I used for testing both deployment methods. you can find it here


Related Posts

Working with git submodules
October 15, 2023
3 min
© 2024, All Rights Reserved.
Powered by formatics

Quick Links

Advertise with usAbout UsContact Us

Social Media