-1

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
https://www.python.org
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/python.rb
==> Dependencies
Build: pkg-config ✘
Required: openssl ✘
Recommended: readline ✘, sqlite ✘, gdbm ✘
==> Options
--quicktest
    Run `make quicktest` after the build (for devs; may fail)
--universal
    Build a universal binary
--with-brewed-tk
    Use Homebrew's Tk (has optional Cocoa and threads support)
--with-poll
    Enable select.poll, which is not fully implemented on OS X (http://bugs.python.org/issue5154)
--without-gdbm
    Build without gdbm support
--without-readline
    Build without readline support
--without-sqlite
    Build without sqlite support
--HEAD
    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
  /usr/local/lib/python2.7/site-packages

See: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md
5
  • "I did a test run by typing in ..." is too vague. Where did you type it in? You ran python? ipython? python3? ipython3? A script with whatever shebang? Tell us where you were "typing in". Also, if you are using an interactive python interpreter, e.g., python, provide the output of type -a python and brew info python.
    – 4ae1e1
    Feb 15, 2015 at 7:03
  • @ksh I run it in the terminal - python. Pasted the info about the brew info into my current thread
    – yan
    Feb 15, 2015 at 7:20
  • I also asked for output of type -a python, which you didn't provide (anyway, I bet it's /usr/bin/python). But based on your brew info python output, your python isn't brewed, so there could be all kinds of PATH problems (note that I said could). Why don't you brew install python and try again with /usr/local/bin/python?
    – 4ae1e1
    Feb 15, 2015 at 7:23
  • By the way, have you reloaded your shell after you edited your .bashrc? If not, do an exec bash first. But in principle you shouldn't need to mess with PYTHONPATH if you just use brewed python.
    – 4ae1e1
    Feb 15, 2015 at 7:25
  • Yea, I did restart my terminal before... I just tried it again and it is still not working :( Also I do not think that I installed any python modules etc?? Not sure if it is part of the Homebrew when I am installing it
    – yan
    Feb 15, 2015 at 7:28

1 Answer 1

0

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.

2
  • I tried again, and it doesn't work. However while searching online, I came across a post that mentions about adding it into .profile and after restarting my terminal, it works! Not sure why it isn't work for .bashrc though but thanks again for your help!
    – yan
    Feb 16, 2015 at 2:28
  • @yan, if you found an answer, you should answer your own question so that others who have the same question in the future can benefit from your learning. Add an answer that you author yourself, and then accept it, providing the same details you would if answering a question that was posted by someone else. Mar 23, 2018 at 13:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .