无法在Pyinstaller中使用–noconsole参数而不崩溃。

huangapple go评论59阅读模式
英文:

Can't use --noconsole of Pyinstaller without crash

问题

I have a little problem. When I run my python code, everything works, and with pyinstaller when I compile it with the console. But when I compile it without console with pyinstaller, it crashes. Do you have an idea ?

我的程序有一个小问题。当我在运行我的Python代码时,一切正常,并且在使用pyinstaller编译时带有控制台也正常。但是当我使用pyinstaller编译时不带控制台,它会崩溃。你有任何想法吗?

My program uses the yt_dlp and pyqt5 libraries. It's a graphical interface that allows to download all kind of videos.

我的程序使用了yt_dlp和pyqt5库。这是一个图形界面,允许下载各种类型的视频。

My repo : https://github.com/Blackfireoff/VOD_Downloader

我的代码库:https://github.com/Blackfireoff/VOD_Downloader

I tried to remove all prints and set the output of yt_dlp to "quiet" so that there are no logs in the console, but this did not change anything.

我尝试删除所有打印并将yt_dlp的输出设置为“quiet”,以便控制台中没有日志,但这没有改变任何情况。

英文:

I have a little problem. When I run my python code, everything works, and with pyinstaller when I compile it with the console. But when I compile it without console with pyinstaller, it crashes. Do you have an idea ?

My program uses the yt_dlp and pyqt5 libraries. It's a graphical interface that allows to download all kind of videos.

My repo : https://github.com/Blackfireoff/VOD_Downloader

I tried to remove all prints and set the output of yt_dlp to "quiet" so that there are no logs in the console, but this did not change anything.

答案1

得分: 0

在开始 QApplication 之前,请添加以下代码以修复它:

# 添加这段代码
import sys
import io

if sys.stderr is None:
    stream = io.StringIO()
    sys.stdout = stream
    sys.stderr = stream

app = QApplication(argv, APP_NAME)

我之前曾经遇到过这个 bug。在我进入出现 bug 的代码后,我发现这个 bug 是因为 sys.stderr 为 None 导致的。因此,它会引发 NoneTypeException(我不记得这个异常叫什么了)。

英文:

Add this code before you start QApplication to fix it:

# Add this
if sys.stderr is None:
    stream = io.StringIO()
    sys.stdout = stream
    sys.stderr = stream

app = QApplication(argv, APP_NAME)

I struggled with this bug before. After I go into the code where the bug happened, I found out that this bug caused because sys.stderr is None. Therefore, it will throw NoneTypeException (I don't remember what is this exception called).

huangapple
  • 本文由 发表于 2023年5月17日 17:30:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270579.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定