【问题标题】:Pyinstaller noconsole option makes exe fatal error [Solved]Pyinstaller noconsole 选项使 exe 致命错误 [已解决]
【发布时间】:2020-01-27 15:22:05
【问题描述】:

嗨,我对编程很陌生。 我用 Anaconda 虚拟环境和

python 3.5.6、pyinstaller 3.5、selenium 3.141、pyqt5 5.13.2、pymysql 0.9.3

它在 atom 中运行良好。 当我这样做时也能正常工作

pyinstaller --onefile myapp.py

但是当我这样做时

pyinstaller --noconsole --onefile myapp.py

在命令提示符中显示已成功完成。 但是当我点击 myapp.exe 时, 出现致命错误按摩框。如下所示

fatal error detected

failed to execute script MyScript

我查了很多,但找不到原因。


我以https://stackoverflow.com/a/47229908/12471379 的身份做了一些工作 仍然不知道如何修复。


01.07.20

现在我什么都没有,当我运行 myapp.exe 时,甚至没有来自 cmd 的 devTool 东西

pyinstaller --onefile myapp.py制作的

仍然不能使用 --noconsole


01.08.20

我刚做了新的venv,没有

pyinstaller --noconsole --onefile --noupx myapp.py

我得到的唯一警告是

23142 INFO: Loading module hook "hook-PyQt5.py"...
23352 WARNING: Hidden import "sip" not found!

但因为它只是警告。我忽略了这一点。 并且不工作 疯了……


01.09.20 问题解决了。

我太愚蠢了……我相信会发生这种情况,因为我对编程很陌生 我会离开这个,所以没有初学者会像我一样犯同样的错误。

如果您的母语不是英语。 您的脚本中可能有一些 unicode 更改。 像这样

import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

我只是从我的讲座视频中复制并粘贴它。所以对此一无所知。还是不知道。我认为这会将错误翻译成我的语言。

问题出在这部分。

import io
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

不知道具体原因。 我只是抹掉它。并将 servier.py 更改为 https://stackoverflow.com/a/51118530/12471379

pyinstaller --clean --noconsole --onefile --noupx myapp.py

有效!!!

我知道这是非常基本的错误。 但我希望这可以帮助一些初学者。

【问题讨论】:

    标签: pyinstaller


    【解决方案1】:

    您的问题似乎与系统标准输出和标准错误sys.stdoutsys.stderr的编码重新配置有关。

    如果您仍想更改stdoutstderr 的编码,以下代码应该可以工作(不会阻止您将pyinstaller--noconsole 选项一起使用):

    import codecs
    if sys.stdout.encoding != 'UTF-8':
        sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
    if sys.stderr.encoding != 'UTF-8':
        sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict')
    

    【讨论】:

      猜你喜欢
      • 2017-04-01
      • 2019-10-19
      • 2016-09-27
      • 2013-02-12
      • 1970-01-01
      • 2021-10-24
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多