Macos – Cannot import module `PyQt4.QtGui`


I am using Mac OS X 10.7.5, have followed and installed the PyQt modules using the "Install homebrew" method as stated in this link but when I did a test run by typing in from PyQt4.QtGui import * I got the following error in my terminal…

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4.QtGui

Checked my .bashrc file, and the contents are as followed:

BREW_PREFIX=`brew --prefix`

export PATH=$BREW_PREFIX/share/python:$BREW_PREFIX/bin/:$BREW_PREFIX/sbin:$PATH

export PYTHONPATH=$BREW_PREFIX/lib/python2.7/site-packages:$PYTHONPATH

Am I still missing something? I seriously need PyQt4. Can someone guide me?
Also, as I am using TextMate, will it work in it as well?

Info from brew info python:

python: stable 2.7.9, HEAD
Not installed
==> Dependencies
Build: pkg-config ✘
Required: openssl ✘
Recommended: readline ✘, sqlite ✘, gdbm ✘
==> Options
    Run `make quicktest` after the build (for devs; may fail)
    Build a universal binary
    Use Homebrew's Tk (has optional Cocoa and threads support)
    Enable select.poll, which is not fully implemented on OS X (
    Build without gdbm support
    Build without readline support
    Build without sqlite support
    Install HEAD version
==> Caveats
Setuptools and pip have been installed. To update them
  pip install --upgrade setuptools
  pip install --upgrade pip

You can install Python packages with
  pip install <package>

They will install into the site-package directory


Best Answer

I'm writing this up as an answer because comments are not a good place for multiline code block. Not guaranteed to work, because OP seems rather confused about his/her environment. (Personally I don't have a clean environment to play with — my brew and python environments are already full of stuff. But I definitely got pyqt working, which I never installed before.)

Assuming your brew installation is in /usr/local, and your shell is bash or zsh, do the following step by step (strip the comments if you haven't turned on interactive comments):

> # edit your .bashrc/.zshenv/.zshrc and get rid of your custom PYTHONPATH;
> # brew will take care of that for you
> export PATH=/usr/local/bin:$PATH
> brew install python pyqt
> exec $SHELL -l # shouldn't need this, but why not?

Now run /usr/local/bin/python and try to from PyQt4.QtGui import * again.