HOWTO: Install PyQt on Mac with Python 3?

Some people watching my Python desktop application development course reported problems installing PyQt on a Mac machine. While I primarily use Arch Linux on my desktop for development, after hearing about this issue from several users, I grabbed my MacBook Pro and decided to see what the problem was, assured of the fact that it’s a two click process.

Here’s the thing: it’s not a two click process. It involved more, but I ended up installing it successfully.


Step 1 – Install Homebrew

The first thing I did is install Homebrew, the missing package manager for Mac. This is similar to e.g. apt-get or yum package managers on some Linux systems.

To install Homebrew, open your terminal and paste this line:

ruby -e "$(curl -fsSL"

Note: it may be a good idea to check the Homebrew homepage in case this command has changed.

Step 2 - Removing existing Python 3 installation

After homebrew has installed, you need to install Python 3. Here’s the caveat: if you already have Python 3 installed and you did not use Homebrew, you’ll have to delete the current installation of Python 3.

If you have Python 3 installed via means other than homebrew, keep reading. Otherwise you do not have Python 3 installed, go to Step 3.

Already have it installed? Okay, to remove Python 3 from your Mac, execute the following command in the Terminal.

cd /usr/local/bin; ls -l . | grep '../Library/Frameworks/Python.framework/Versions/3.4' | awk '{print $9}' | xargs rm

Note: this is meant for Python 3.4. If you’re from the future, you may have a later version installed – simply change 3.4 with whatever version you have installed.

That’s it. Python 3 should now be removed. Now let’s install it using Homebrew.

Step 3 - Installing Python 3 using Homebrew

To install Python 3 using homebrew, simply open the Terminal and execute the following command:

brew install python3

Ok, now we need to (finally) install PyQt and its dependencies.

Step 4 - Installing PyQt4

This is also fairly simple. In terminal, execute these commands in order:

brew install qt
brew install sip --with-python3
brew install pyqt --with-python3

Wait for this to finish – it may take a while.

That’s it! You should now have a working PyQt installation on your Mac.