简体   繁体   English

PyQt4导入错误

[英]PyQt4 Import Error

I have downloaded PyQt4 and have been able to use it without any issues in Idle. 我已经下载了PyQt4,并且能够在空闲状态下使用它而没有任何问题。 However, when I am trying to execute a command in terminal, I am receiving the error 但是,当我尝试在终端中执行命令时,出现错误

ImportError: No module named PyQt4

在此处输入图片说明

The code I ran is the following: 我运行的代码如下:

User-MacBook-Pro:Python $ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
User-MacBook-Pro:Python $ pyuic4 Print.ui>Print_ui.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyQt4/uic/pyuic.py", line 26, in <module>
    from PyQt4 import QtCore
ImportError: No module named PyQt4

I would love to get some guidance on this issue. 我希望就此问题获得一些指导。

Thank you 谢谢

I have solved the same problems, I find that the problem is in file 'pyuic4'. 我已经解决了同样的问题,发现问题出在文件'pyuic4'中。 The wrong version python was setted. 设置了错误的python版本。

You can run code-- which pyuic4 --to find where is the pyuic4, and then open this file by texteditor(eg.Sublime Text). 您可以运行代码- which pyuic4 --to找到哪里是pyuic4,然后通过文本编辑(eg.Sublime文本)打开这个文件。 After that, you will find one row code in this file: 之后,您将在此文件中找到一个行代码:

#!/bin/sh
exec pythonw2.7 //anaconda/lib/python2.7/site-packages/PyQt4/uic/pyuic.py ${1+"$@"}

So, the function of pyuic4 is to call pythonw2.7 and run pyuic.py . 因此, pyuic4的功能是调用pythonw2.7并运行pyuic.py

In my computer, I have installed anaconda so the PyQt4 file is stored in anaconda PATH, but pythonw2.7 will use the Apple supplid Python. 在我的计算机上,我已经安装了anaconda因此PyQt4文件存储在anaconda PATH中,但是pythonw2.7将使用Apple提供的Python。 Under the circumstance, pythonw2.7 can't import the module PyQt4. 在这种情况下,pythonw2.7无法导入模块PyQt4。 Changing it to pythonw which belongs to anaconda will solve the problem. 将其更改为属于蟒蛇的pythonw将解决此问题。

In your problem, I think you can check out the python version, and change the default version of pythonw in pyuic.py to right version. 在您的问题中,我认为您可以签出python版本,并将pyuic.py的pythonw的默认版本更改为正确的版本。

Just use pythonw to run the following file: 只需使用pythonw运行以下文件:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyQt4/uic/pyuic.py

If the return result is: 如果返回结果是:

Error: one input ui-file must be specified

rather than: 而不是:

Traceback (most recent call last):
  File "//anaconda/lib/python2.7/site-packages/PyQt4/uic/pyuic.py", line 26, in <module>
    from PyQt4 import QtCore
ImportError: No module named PyQt4

the pythonw is the right version. pythonw是正确的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM