在Windows 7中安装PyQt5

2024-05-20 19:39:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Python 3.4编写了一个程序,我想为它制作一个GUI。我发现PyQt5-是它的工具。

1)我下载并安装了PyQt5(http://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.4.1/PyQt5-5.4.1-gpl-Py3.4-Qt5.4.1-x32.exe)的二进制软件包。

2)我试图用Python运行这个示例代码:

import sys
from PyQt5.QtWidgets import QApplication, QWidget


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()

    sys.exit(app.exec_())

Python返回en错误:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\PyQt5.py", line 2, in <module>
    from PyQt5.QtWidgets import QApplication, QWidget
  File "D:\PyQt5.py", line 2, in <module>
    from PyQt5.QtWidgets import QApplication, QWidget
ImportError: No module named 'PyQt5.QtWidgets'; 'PyQt5' is not a package

3)我找到了安装QT的建议。所以,我下载并安装了QT(http://download.qt.io/official_releases/online_installers/qt-opensource-windows-x86-online.exe)。

4)然后我卸载并再次安装了PyQt5的二进制软件包。 没有结果。

如果运行以下命令,Python不会返回任何错误:

import PyQt5

但如果我想逃跑:

from PyQt5.QtWidgets import QApplication, QWidget

它返回与开头相同的错误。

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\PyQt5.py", line 2, in <module>
    from PyQt5.QtWidgets import QApplication, QWidget
  File "D:\PyQt5.py", line 2, in <module>
    from PyQt5.QtWidgets import QApplication, QWidget
ImportError: No module named 'PyQt5.QtWidgets'; 'PyQt5' is not a package

我做错什么了?


Tags: infromimportmostlinecallpyqt5file