【发布时间】:2020-11-02 19:37:06
【问题描述】:
我正在开发一个 GUI 应用程序,我希望将我的 python 代码转换为可执行文件。
当作为 .py 文件运行时,该程序可以正常运行。但是,当我尝试使用 pyinstaller --onedir 将其转换为 .exe 时,它编译我的程序没有任何错误,但是当我双击 .exe 时,它不起作用。控制台会立即打开并立即关闭。没有错误,但也没有 GUI 窗口。
即使我改用 auto-py-to-exe,同样的问题仍然存在。我被困在这里,不胜感激。谢谢。
编辑:我没有双击.exe,而是尝试从cmd运行它,错误追溯到我的虚拟环境的站点包中的markdown文件夹。
exec(bytecode, module.__dict__)
File "lib\site-packages\markdown\htmlparser.py", line 30, in <module>
File "<frozen importlib._bootstrap>", line 580, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'
[8788] Failed to execute script app
htmlparser.py文件中这部分内容如下:
spec = importlib.util.find_spec('html.parser')
htmlparser = importlib.util.module_from_spec(spec)
spec.loader.exec_module(htmlparser)
sys.modules['htmlparser'] = htmlparser
注意:我有(Python==3.7.9,Pyinstaller==3.6,auto-py-to-exe==2.7.8)。我发现了一个类似的问题here,但没有任何令人满意的答复。
【问题讨论】:
-
尝试从现有命令提示符运行 exe,而不是双击 exe。然后,您应该能够看到错误消息,然后在不清楚如何解决问题时用这些消息更新您的问题。
-
你正在使用哪些库,你的文件目录对于程序来说是什么样的?
-
@MarkAdamson 我已经编辑了问题,其中包含从 cmd 运行 .exe 时发现的错误。
-
@Davidsherriff 我主要使用 pandas、numpy、datetime、PyQt5、tabulate 等。如果我正确理解您关于文件目录的问题,我的文件目录中有 7 个子文件夹,包含我使用的不同文件类型在程序中(图像、JSON、xlsx 等)。
-
@videzign 是根文件夹中的主脚本吗?生成 exe 时从主脚本调用其他脚本可能存在问题
标签: python python-3.x exe pyinstaller