pyinstaller 代码无法按预期工作后?
After pyinstaller code does not work as expected?
此代码在 .py 格式时运行良好。第二个我使用 pyinstaller 和这个“pyinstaller.exe --one-file --windowed --icon=app.ico BootcampManager.py” 行为很奇怪并且不做它通常做的事情。它卡在“更新状态”。 None 个按钮有效。
尝试将 --onefile
替换为 --onedir
:
pyinstaller.exe --onedir --windowed --icon=app.ico BootcampManager.py
如果这不起作用,则尝试从 .py
转换为 .pyw
并删除 --windowed
pyinstaller.exe --onedir --icon=app.ico BootcampManager.pyw
编辑
根据我使用 pyinstaller
的经验,当 exe 表现 "weird"
时,这是因为所有库 (DLLs
) 都 statically linked
到可执行文件中,即--onefile
是什么意思。
当你 link 它们 dynamically
(--onedir
) 时,它们是在运行时或“导入时”导入的,因此可执行文件不需要在之后加载所有库你打开它。这意味着可执行文件将 faster
和更多 efficient
.
这可能不是 OP 问题的直接答案。但我在 MacOS 中遇到了同样的问题。就我而言,我试图在与可执行文件相同的路径中写入一个文件。
with open("myFile.txt", 'w') as f:
f.write("Some texts")
这在我从代码 运行 时有效,但是当我使用 pyinstaller --onefile
创建可执行文件并执行它时,它会将自己提取到主文件夹中并尝试在其中 运行 ,它没有写访问权限。所以它失败了。我也看不到错误日志。
解决方案是使用绝对路径。
with open("/Users/kmchmk/Documents/myProject/dist/myFile.txt", 'w') as f:
f.write("Some texts")
此问题仅在具有 --onefile
选项的 MacOS 中发生。我已经尝试 Windows 和 Ubuntu 并且没有任何问题。
此代码在 .py 格式时运行良好。第二个我使用 pyinstaller 和这个“pyinstaller.exe --one-file --windowed --icon=app.ico BootcampManager.py” 行为很奇怪并且不做它通常做的事情。它卡在“更新状态”。 None 个按钮有效。
尝试将 --onefile
替换为 --onedir
:
pyinstaller.exe --onedir --windowed --icon=app.ico BootcampManager.py
如果这不起作用,则尝试从 .py
转换为 .pyw
并删除 --windowed
pyinstaller.exe --onedir --icon=app.ico BootcampManager.pyw
编辑
根据我使用 pyinstaller
的经验,当 exe 表现 "weird"
时,这是因为所有库 (DLLs
) 都 statically linked
到可执行文件中,即--onefile
是什么意思。
当你 link 它们 dynamically
(--onedir
) 时,它们是在运行时或“导入时”导入的,因此可执行文件不需要在之后加载所有库你打开它。这意味着可执行文件将 faster
和更多 efficient
.
这可能不是 OP 问题的直接答案。但我在 MacOS 中遇到了同样的问题。就我而言,我试图在与可执行文件相同的路径中写入一个文件。
with open("myFile.txt", 'w') as f:
f.write("Some texts")
这在我从代码 运行 时有效,但是当我使用 pyinstaller --onefile
创建可执行文件并执行它时,它会将自己提取到主文件夹中并尝试在其中 运行 ,它没有写访问权限。所以它失败了。我也看不到错误日志。
解决方案是使用绝对路径。
with open("/Users/kmchmk/Documents/myProject/dist/myFile.txt", 'w') as f:
f.write("Some texts")
此问题仅在具有 --onefile
选项的 MacOS 中发生。我已经尝试 Windows 和 Ubuntu 并且没有任何问题。