【问题标题】:Import QApplication fails without error (python3)导入 QApplication 失败且没有错误(python3)
【发布时间】:2015-01-03 03:54:49
【问题描述】:

我正在尝试在 python 脚本中实现Take a screenshot via a python script. [Linux] 提供的解决方案:

from PyQt5.QtWidgets import QApplication
app = QApplication([])
screen = app.primaryScreen()
screenshot = screen.grabWindow(QApplication.desktop().winId())
screenshot.save('/tmp/screenshot.png')

运行此代码时,python 会停止工作而不会产生错误。

BTO-user@BTO /srcpython/fod
Python 3.2.5 (default, Jul 28 2014, 01:44:48)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5.QtWidgets import QApplication

BTO-user@BTO /srcpython/fod

模块 PyQt5 已安装,但这些是 .dll 文件。通常,当我安装模块时,应该有源文件。这些 dll 文件应该绑定到 Qt5,我通过 cygwin dev 安装程序安装了它。这两个安装中的一个可能有问题,但我已经尝试了很多重新安装。它让我感到困扰,没有一个错误报告。

【问题讨论】:

  • 你必须在cygwin上这样做吗?我希望 Windows 版本可以工作。
  • windows cmd 中的相同错误:Microsoft Windows [版本 6.3.9600] (c) 2013 Microsoft Corporation。版权所有。 C:\Users\BTO-user>python3.2m Python 3.2.5 (default, Jul 28 2014, 01:44:48) [GCC 4.8.3] on cygwin 输入“help”、“copyright”、“credits”或“许可证”以获取更多信息。 >>> from PyQt5.QtWidgets import QApplication C:\Users\BTO-user> (不知道怎么粘贴好)
  • 我的意思是 windows python,python3.2m 是 cygwin python。还是你必须使用cygwin python?
  • 这似乎确实有所作为。 C:\Python33>python.exe Python 3.3.2 (v3.3.2:d047928ae3f6, May 16, 00:03:43) [MSC v.1600 32 bit (In tel)] on win32 输入“help”、“copyright”、“credits”或“license”以获取更多信息。 >>> from PyQt5.QtWidgets import QApplication Traceback(最近一次调用最后):文件“”,第 1 行,在 ImportError: No module named 'PyQt5.QtWidgets' >> 虽然 QtWidgets.dll 在存储库中?
  • cygwin 不是 Windows 的包管理器,它们是两个独立的东西。你需要在windows上重新安装pyqt。

标签: python cygwin qt5 pyqt5


【解决方案1】:

@simonzack 的建议导致了解决方案。我在 cygwin 环境中运行了该命令,但在正常的 windows 环境中运行后,它给出了更多描述性(或多或少)的错误。

[DLL加载失败的错误:找不到指定的模块,通过组合动作解决:

【讨论】:

    猜你喜欢
    • 2011-01-09
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    相关资源
    最近更新 更多