【问题标题】:Executable from Python2 script w. PyInstaller: Qt4 module import error可从 Python2 脚本 w 执行。 PyInstaller:Qt4 模块导入错误
【发布时间】:2015-12-10 20:21:50
【问题描述】:

我有一个在 Qt Designer 中创建并使用 pyuic 编译的 GUI 项目。所以我从 PyQt4 导入 QtCore 和 QtGui。

脚本运行正常

我需要一个可执行文件。该工具是 PyInstaller,目标平台 - Linux 和 Windows。我已经尝试过一次并取得了成功。然后我开发了一个项目一段时间,现在......我无法制作可执行文件 - 它崩溃了

ImportError:没有名为 QtCore 的模块

问题是我无法将当前项目与旧项目进行比较。而且我不确定我的 PC 中的环境发生了怎样的变化。

所以我必须明白为什么 PyInstaller 会生成一个可执行文件没有错误消息 - 但程序会崩溃。或者如何帮助 PyInstaller(我已阅读 manual 并从中尝试了很多但无济于事)。

这是我的项目的简化版本(实际上是一个文件),它具有主要功能:它可以从 Python 运行并作为独立程序崩溃。

#!/usr/bin/python
# -*- coding: utf-8 -*-
""" test script to learn PyInstaller usage
"""
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui


class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_ADCmonitor()
        self.ui.setupUi(self)
        self.exitAction = QtGui.QAction('Exit', self)
        self.exitAction.setShortcut('Ctrl+Q')
        self.exitAction.triggered.connect(self.close)
        toolbar = self.addToolBar('Exit')
        toolbar.addAction(self.exitAction)
        self.refresh = QtCore.QTimer()
        self.status_freeze_timer = QtCore.QTimer()
        self.update_data()

    def update_data(self):
        self.status_refresh('Ok')
        self.refresh.singleShot(200, self.update_data)

    def status_refresh(self, msg):
        self.ui.statusbar.showMessage(msg)


class Ui_ADCmonitor(object):
    def setupUi(self, ADCmonitor):
        ADCmonitor.setObjectName("ADCmonitor")
        ADCmonitor.resize(300, 300)
        self.statusbar = QtGui.QStatusBar(ADCmonitor)
        self.statusbar.setObjectName("statusbar")
        ADCmonitor.setStatusBar(self.statusbar)
        QtCore.QMetaObject.connectSlotsByName(ADCmonitor)
        ADCmonitor.setWindowTitle("ADC Monitor")


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    window = Main()
    window.show()
    sys.exit(app.exec_())

请不要建议我使用其他 dist 实用程序。我尝试了其中的一些,我选择了 PyInstaller,我想使用它。

【问题讨论】:

  • 或者stackoverflow.com/questions/8548904/…?看起来谷歌上有很多潜在的解决方案你试过了吗?您使用的是什么版本的 pyinstaller?您正在构建什么操作系统?什么版本的python?什么版本的pyQT?
  • Joran,也许第一个链接是一个答案。我将不得不尝试安装 PyInstaller 2.2。我的操作系统是 Linux Mint,PyInstaller 是 2.1,Python 是 2.7.5+
  • 对不起:/我希望我能提供更多帮助......第二个答案实际上看起来更适用于我......但也许不是
  • 乔兰,你真的帮了我大忙。非常感谢!

标签: python qt executable pyinstaller


【解决方案1】:

所以,问题出在 PyInstaller 2.1 错误中 - 正如 Joran Beasley 所假设的那样。

解决方案:

sudo pip install git+https://github.com/pyinstaller/pyinstaller.git

还有宾果游戏!

pyinstaller myscript.py 执行正确。

【讨论】:

  • Stack Overflow 中的 Newbee。我可以将评论标记为有用吗?
猜你喜欢
  • 2017-05-18
  • 2013-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-20
  • 1970-01-01
  • 2018-06-26
相关资源
最近更新 更多