开发者

PyQt4 in Snow Leopard using Homebrew

I'm new to Mac world and I'm trying to set up a Python + Qt + PyQt development environment in my OS X 10.6 Snow Leopard.

Currently, I have installed latest Qt Creator from Trolltech's website including also SIP, Python 2.7 and PyQt4 using Homebrew, but after these installation procedures, when I run >> import PyQt4 in python interpreter, it reports that no PyQt4 modules have been installed.

What could cause开发者_如何学Go this problem?


This would enable PyQT4 on OS X even if you are using the brew version or OS X version of Python.

Obviously you still have to install pyqt using brew: brew install pyqt

Edit ~/.bash_profile and add these lines:

if [ -d /usr/local/lib/python2.7/site-packages ]; then
     export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
fi

This will work with OS X 10.7, 10.8 and 10.9 and in addition to this it will enable all Python modules installed by brew.


try

export PYTHONPATH=/usr/local/lib/python:$PYTHONPATH

If it works, you can put it in your shell's initialization file (e.g. ~/.bash_profile or ~/.zshenv).


I had to do this for PySide, the Qt project's new python library, but the solution will work for you as well.

Locate the site-packages directory of the module. Running a find /usr/local/Cellar -iname "pyside*" in your terminal where /usr/local/Cellar is the install location for homebrew software and pyside is the name of the module. The find command should print a number of directories, one (or more) of these should be a sub directory of a site-packages directory. In my case, the module was located at /usr/local/Cellar/pyside/1.1.2/lib/python2.7/site-packages/PySide.

Now find python's site-packages directory. I'm not sure where it is by default as I've installed so many versions of python. To find it for the primary python you can run python -c 'import sys; from pprint import pprint; pprint(sys.path)'. There should be a directory in the output something along the lines of '/Library/Python/2.7/site-packages' which you're looking for.

Now create a .pth (a path configuration file) in this directory to add the module's site-packages to python's module search path. Do this (as root if needed) with echo '/usr/local/Cellar/pyside/1.1.2/lib/python2.7/site-packages' > /Library/Python/2.7/site-packages/pyside.pth using the directories you found in place of mine. That should do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜