PyQt5应用程序与PyInstaller一起构建

2024-09-20 04:01:08 发布

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

  • MacOS 10.14
  • Python 3.7.1
  • PyInstaller最新版本于2019年9月24日从{}下载

我试图用PyQt5PyInstaller构建一个应用程序。我可以用下面的小脚本(script1):在我cd脚本所在的目录之后,我只运行PyInstaller script.py。然后它构建了应用程序,我可以在新创建的子目录中找到可执行文件path/to/script/dist/script/在这个目录中有一个可执行文件,你可以双击它,应用程序就会运行。然后我试着用一个更大的脚本做同样的操作(script2,对于错误消息称为image_viewer_24_02_2019.py),我找到了there。然后我尝试运行可执行文件(在path/to/script/dist/script/)中,但是我得到了以下错误消息。在构建脚本2时,问题的根源是什么?在

注意,使用pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip安装最新版本后,问题仍然存在

顺序如下:脚本1(可以成功构建)、脚本2(无法构建)及其错误消息

脚本1(可以成功构建)

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize

class HelloWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(640, 480))
        self.setWindowTitle("Hello world")

        centralWidget = QWidget(self)
        self.setCentralWidget(centralWidget)

        gridLayout = QGridLayout(self)
        centralWidget.setLayout(gridLayout)

        title = QLabel("Hello World from PyQt", self)
        title.setAlignment(QtCore.Qt.AlignCenter)
        gridLayout.addWidget(title, 0, 0)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainWin = HelloWindow()
    mainWin.show()
    sys.exit( app.exec_() )

脚本2(可以构建,但应用程序无法运行)

^{pr2}$

错误消息(在启动用脚本2创建的应用程序之后)

Last login: Sun Feb 24 14:39:36 on ttys001
You have new mail.
-bash: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
/Users/mymac/Documents/PyQt/image_viewer_24_02_2019/build/image_viewer_24_02_2019/image_viewer_24_02_2019 ; exit;
(base) mymacs-MacBook-Pro:~ mymac$ /Users/mymac/Documents/PyQt/image_viewer_24_02_2019/build/image_viewer_24_02_2019/image_viewer_24_02_2019 ; exit;
[45194] Error loading Python lib '/Users/mymac/Documents/PyQt/image_viewer_24_02_2019/build/image_viewer_24_02_2019/libpython3.7m.dylib': dlopen: dlopen(/Users/mymac/Documents/PyQt/image_viewer_24_02_2019/build/image_viewer_24_02_2019/libpython3.7m.dylib, 10): image not found
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

Tags: fromimageimportself脚本应用程序消息错误