[英]ImportError: No module named PyQt4
I installed pyqt4 by using Homebrew. 我使用Homebrew安装了pyqt4。 But when I import PyQt4 in python interpreter, It said that "No module named PyQt4".
但是当我在python解释器中导入PyQt4时,它说“没有名为PyQt4的模块”。 Can somebody help me with that?
有人可以帮我吗?
After brew install pyqt
, you can brew test pyqt
which will use the python you have got in your PATH in oder to do the test (show a Qt window). brew install pyqt
,您可以brew test pyqt
,它将使用您在PATH路径中获得的python进行测试(显示Qt窗口)。
For non-brewed Python, you'll have to set your PYTHONPATH as brew info pyqt
will tell. 对于未酿造的Python,您必须按照
brew info pyqt
会告诉您的那样设置PYTHONPATH。
Sometimes it is necessary to open a new shell or tap in order to use the freshly brewed binaries. 有时有必要打开一个新的外壳或点击以使用新鲜酿造的二进制文件。
I frequently check these issues by printing the sys.path from inside of python: python -c "import sys; print(sys.path)"
The $(brew --prefix)/lib/pythonX.Y/site-packages
have to be in the sys.path
in order to be able to import stuff. 我经常通过从python内部打印sys.path来检查这些问题:
python -c "import sys; print(sys.path)"
$(brew --prefix)/lib/pythonX.Y/site-packages
必须位于sys.path
中,以便能够导入内容。 As said, for brewed python, this is default but for any other python, you will have to set the PYTHONPATH
. 如前所述,对于brewed python,这是默认设置,但是对于其他任何python,您都必须设置
PYTHONPATH
。
You have to check which Python you are using. 您必须检查使用的是哪个Python。 I had the same problem because the Python I was using was not the same one that brew was using.
我遇到了同样的问题,因为我使用的Python与brew使用的Python不同。 In your command line:
在您的命令行中:
which python
which brew
cd /usr/local/lib/python2.7/site-packages
ls
//you can see PyQt4 and sip are here ls
//您可以在此处看到PyQt4和sip usr/local/lib/python2.7/site-packages
to your python path. usr/local/lib/python2.7/site-packages
到您的python路径。 open ~/.bash_profile
//you will open your bash_profile file in your editor open ~/.bash_profile
//您将在编辑器中打开bash_profile文件 'export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH'
to your bash file and save it 'export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH'
到您的bash文件中并保存 python
import PyQt4
// it is ok now import PyQt4
//现在可以 If you're using Anaconda to manage Python on your system, you can install it with: 如果您正在使用Anaconda在系统上管理Python,则可以使用以下命令进行安装:
$ conda install pyqt=4
Omit the =4
to install the most current version. 忽略
=4
以安装最新版本。
Answer from How to install PyQt4 in anaconda? 如何在Anaconda中安装PyQt4的答案?
I solved the same problem for my own program by installing python3-pyqt4
. 我通过安装
python3-pyqt4
为自己的程序解决了相同的问题。
I'm not using Python 3 but it still helped. 我没有使用Python 3,但仍然有帮助。
It is likely that you are running the python executable from /usr/bin (Apple version) instead of /usr/loca/bin (Brew version) 您可能是从/ usr / bin(Apple版本)而不是/ usr / loca / bin(Brew版本)运行python可执行文件
You can either 你可以
a) check your PATH variable a)检查您的PATH变量
or 要么
b) run brew doctor
b)
brew doctor
or 要么
c) run which python
c)运行
which python
to check if it is the case. 检查情况是否如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.