2017-08-08 134 views
0

我在很多帖子中已經看到這個問題,但沒有任何答案對我有幫助。 所以,這是我的問題。無法從PyQt4導入QtGui

我在窗戶上。 我有蟒蛇3.6版本

1)我下載中心車輪文件(PyQt4中的PyQt4-4.11.4-CP36-cp36m-win_amd64.whl)有: http://www.lfd.uci.edu/~gohlke/pythonlibs/

而且我在這裏保存的是:C: \用戶\安妮 - 索菲•

2)我打開一個shell窗口admin和我運行 「PIP安裝PyQt4-4.11.4-CP36-cp36m-win_amd64.whl」

安裝似乎即使工作我收到消息:

Requirement 'PyQt4-4.11.4-cp36-cp36m-win_amd64.whl' looks like a filename, but the file does not exist 

當我重新運行 「PIP安裝PyQt4-4.11.4-CP36-cp36m-win_amd64.whl」 我仍然得到這個消息,但我也得到"Requirement already satisfied: PyQt4==4.11.4 from file:///C:/WINDOWS/system32/PyQt4-4.11.4-cp36-cp36m-win_amd64.whl in c:\users\anne-sophie\anaconda3\lib\site-packages"

3)現在,當我打開一個Python筆記本並寫上「import PyQt4」我沒有得到任何錯誤。

但是,當我寫from PyQt4 import QtGui我得到的錯誤信息:ImportError: cannot import name 'QtGui'

4)我去C:\Users\Anne-Sophie\Anaconda3\Lib\site-packages\PyQt4,我看到QtGui不是PyQt4中,但PyQt4中/ SIP所以我寫from PyQt4.sip import QtGui這是工作... 。

5)我去這個網站beginers與PyQt4的: https://pythonprogramming.net/basic-gui-pyqt-tutorial/

而且我寫的:

import sys 
from PyQt4.sip import QtGui 
app = QtGui.QApplication(sys.argv) 

我得到的錯誤:AttributeError: module 'PyQt4.sip.QtGui' has no attribute 'QApplication'

Finally here are my questions:

Q1: do you think that Requirement 'PyQt4-4.11.4-cp36-cp36m-win_amd64.whl' looks like a filename, but the file does not exist is a problem (step 2) if import PyQt4 is working?

Q2: do you know what I am doing wrong? nobody is using from PyQt4.sip import QtGui so I am not sure that I should do it..... Moreover, even when I do it, I still get error when I go further

Q3: does someone know how to make it work?

回答

0

Q1:我認爲你的錯誤消息('PyQt4-4.11.4-cp36-cp36m-win_amd64.whl' looks like a filename, but the file does not exist),因爲您從不同的目錄下保存輪文件pip命令,所以點無法找到車輪文件。它可能會繼續並從Python Package索引中下載它,因爲第二次運行Pip時,它說PyQt4已經安裝。

Q2:不,您的進口報表中不應該有sip。只要from PyQt4 import QtGui應該工作。您的安裝有問題。

Q3:問題是最有可能是您使用pip旁邊pyqt包蟒蛇的安裝PyQt4(你可以檢查此與conda list命令)。你不能這樣做PyQt。 Pip和Anaconda通常可以很好地協同工作,但是在PyQt的情況下,它們並不是因爲軟件包名稱不同。

我建議您重新安裝Anaconda,然後僅使用Anaconda安裝PyQt。

也許你已經試過這個,但用pip去,因爲PyQt4不適用於Python 3.6。如果你只想試試這個教程,你可以降級到Python 3.5。另一種選擇是使用PyQt5。與PyQt4最大的區別在於QtGui包已被拆分爲QtWidgetsQtGui。因此,將示例翻譯成PyQt5應該很容易。