【问题标题】:PyInstaller just opens .exe file when debug=True or console=TruePyInstaller 仅在 debug=True 或 console=True 时打开 .exe 文件
【发布时间】:2020-10-07 13:31:16
【问题描述】:

这是正在发生的事情:

  • 1 - 使用 debug=True 冻结 => 生成 .exe 文件,运行 .exe 没有出现 Windows 控制台。这很好,但我认为离开 debug=True 不是正确的做法。
  • 2 - 使用 console=True 冻结 => 生成 .exe 文件,但是当我单击图标打开 .exe 文件时会打开 Windows 控制台。 当我通过公共线打开文件时,它不会打开 Windows 控制台。
  • 3 - 使用 console=False 和 debug=False 冻结 => 生成 .exe 文件没有错误,但是当我“打开” .exe 文件时,什么也没有显示 向上。在命令行中,该命令似乎已运行并且 什么也没发生。

知道为什么我的 .exe 文件在可执行文件_3.spec 文件中使用 console=False 和 debug=False 生成它时无法正常运行吗?

.exe 文件是指 dist/executable_package_V3/EXE_NAME.exe

我正在使用 pyi-makespec executable_3.py 创建我的 executable_3.spec 文件(我使用的是 Windows 10 和 Python 3.7.7,但也尝试使用 Python 3.6.10 和 3.5.6 并获得了相同的结果。)然后运行pyinstaller executable_3.spec

图书馆:

  1. pyinstaller=4.0.dev0
  2. pyqt5=5.11.3

经过一些更改,这就是我的 executable_3.spec 的样子

我的 executable_3.spec 文件:

    # -*- mode: python ; coding: utf-8 -*-

block_cipher = None

added_files = []

a = Analysis(['src\\executable_3.py'], #executable file path
             pathex=['C:\\Users\\MY_NAME\\Documents\\GitHub\\PROJECT_NAME'],
             binaries=[],
             datas=added_files,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='EXE_NAME', 
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False)
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='executable_package_V3')

我的可执行文件_3.py 文件

from GUI import QtCore, QtWidgets, Ui_Dialog #GUI is my UI from Qt Designer
import sys

app = QtCore.QCoreApplication.instance()
if app is None:
    app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_Dialog()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

【问题讨论】:

  • 使用pyinstaller --windowed app.py
  • 我不是从我的 python 文件生成应用程序,而是使用 .spec 文件。我已经尝试过 pyinstaller --windowed executable_3.spec。我没有帮忙。另外,.spec文件中的console=False是不是也产生了同样的效果?
  • 我建议您测试导致问题的库,我已将其用于 PyQt5,它不会产生任何问题。也许其他一些库需要控制台
  • 我删除了所有非必要的库,仍然得到同样的东西

标签: python python-3.x pyqt5 pyinstaller


【解决方案1】:

更新 pyinstaller 对我有用!

我在 4.0 版本并转到 4.3,查看发行说明,我看到了我认为是 4.2 版本解决的这个拉取请求:https://github.com/pyinstaller/pyinstaller/pull/5446

【讨论】:

    猜你喜欢
    • 2022-10-21
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 2021-10-30
    • 2022-07-14
    • 1970-01-01
    • 2020-07-27
    相关资源
    最近更新 更多