我使用的是 Mac OS X 10.7.5,按照本文所述,使用“安装自制软件”方法安装了 PyQt 模块关联但是当我通过输入进行测试运行时,from PyQt4.QtGui import *
我的终端出现以下错误......
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4.QtGui
检查了我的.bashrc文件,内容如下:
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
我还缺少什么吗?我真的需要 PyQt4。有人可以指导我吗?另外,因为我正在使用 TextMate,它也能在其中工作吗?
信息来自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
答案1
我把这个写成答案是因为注释不适合多行代码块。不能保证能用,因为 OP 似乎对他/她的环境相当困惑。(就我个人而言,我没有一个干净的环境可以玩——我的 brew 和 python 环境已经充满了东西。但我肯定可以pyqt
工作了,这是我以前从未安装过的。)
假设你的 brew 安装在 中/usr/local
,并且你的 shell 是 bash 或 zsh,请逐步执行以下操作(如果你尚未打开交互式注释,请删除注释):
> # 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?
现在运行/usr/local/bin/python
并再试from PyQt4.QtGui import *
一次。