8

I am trying to install PyQT and I used PyQT. Is has been installed using home brew. But When I try to import it, python can't. I get the following warning in Home brew. I am new to Mac and can't figure out how to change the python path. Any help would be great.

For non-homebrew python (2.x), you need to amend your PYTHONPATH like so: export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

Trying_hard
  • 8,931
  • 29
  • 62
  • 85

2 Answers2

16

You should edit ~/.bash_profile (create the file if it does not exist) to set the PYTHONPATH environment variable:

export PYTHONPATH=`brew --prefix`/lib/python2.7/site-packages:$PYTHONPATH
mipadi
  • 398,885
  • 90
  • 523
  • 479
  • 1
    So in my travels I've learned that `PYTHONPATH` may be expected by various ways that python projects want you to install them. On OS X, when you install Python using `brew`, it does not provide you with `PYTHONPATH` (and indeed you'll likely need to micromanage it in your shell's init script). This appears to not be an issue if you can find a way to install whatever python project it is using `pip`. – Steven Lu Aug 11 '13 at 08:22
  • 3
    Just a reminder that whenever you change your `.bash_profile` you should restart your terminal or run `source ~/.bash_profile`. – amccormack Apr 30 '15 at 17:56
  • There is a serious flaw with this approach: it breaks Python 3 and making it unusable. That's because by setting PYTHONPATH you force both py2 and py3 to use the same values. – sorin Nov 20 '16 at 09:50
0

Since you installed PyQt by using Homebrew, you should also use Homebrew Python 2.

To install it, run: brew install python

Now, you can import PyQt normally.

Minh Nguyen
  • 310
  • 2
  • 4
  • 11