Installing PyQt on Mac OS X

There are three options for installing PyQt that we will discuss:

  • Using an installer
  • Using MacPorts
  • Installing from source

All of the options are limited in some way and you will need to decide which is best for you. This situation changes frequently as new versions of utilities are released.

Using an installer

The easiest way to install PyQt is to use an installer package that someone else has created. Unfortunately, at this time there is only an installer for Python 3.2 and cx_Freeze (which we use to distribute applications) does not work under this installation.

However, if you can live with these constraints then it is easily the best choice. To install PyQt using the installer you should:

Using MacPorts

MacPorts is a package manager for Mac OS X that makes working with Unix utilities easier. It is currently our preferred method of installing Python 3.3 and PyQt 4.9.4 as it allows us to work with cx_Freeze, which we use to create stand-alone applications.

Follow our guide to distributing your application to install PyQt4 via MacPorts

Installing from source

This option is included for completeness and is not recommended unless you are experienced with the command line.

These instructions are known to work on Mac OS X 10.6.8, 10.7.5 and 10.8.2.With earlier or later versions of the OS your mileage may vary.

  1. Make sure you have the latest Mac OS X Update installed (10.6.8 or 10.7.5 or 10.8.2)
  2. Make sure you have the latest version of Xcode installed (available from the Mac App Store)
  3. From within Xcode ensure you have installed the Command Line Tools (see Xcode -> Preferences -> Downloads)
  4. Create a separate user account with administration privileges
  5. Log out of your regular account and then log into the account you just created
  6. Download and install the most recent Python installation from the Python website
  7. Download the Qt Libraries 4.8.4 from Qt Project
  8. Run the Qt installer and wait for it to finish
  9. Download the latest version of SIP from Riverbank Computing
  10. Download the latest version PyQt from Riverbank Computing
  11. Create a new folder called 'OpenSource' inside your user directory
  12. Move the SIP and PyQt tar.gz packages to this folder
  13. Double-click on the SIP and PyQt tar.qz to decompress them
  14. Rename the SIP and PyQt folders something shorter e.g. 'SIP' and 'PyQt'
  15. In Terminal type the following to install SIP (each line separately followed by enter):
    • cd ~/OpenSource
    • cd SIP
    • python3 -d /Library/Python/3.3/site-packages --arch x86_64
    • make
    • sudo make install
  16. In Terminal type the following to install PyQt4 (each line separately followed by enter):
    • cd ..
    • cd PyQt
    • python3 -d /Library/Python/3.3/site-packages/ --use-arch x86_64
    • make
    • sudo make install
  17. Log out of the new user account and back into your regular account
  18. Check PyQt is working
  19. Delete the recently created user account from system preferences/accounts

You should now be able to run Python programs that use PyQt4 on your Mac.