[英]After pyinstaller code does not work as expected?
This code works fine when it's.py.此代码在 .py 时工作正常。 The second i use pyinstaller with this "pyinstaller.exe --one-file --windowed --icon=app.ico BootcampManager.py" acts weird and does not do what it normally do.
第二个我将 pyinstaller 与这个“pyinstaller.exe --one-file --windowed --icon=app.ico BootcampManager.py”一起使用,行为很奇怪,并且不做它通常做的事情。 It's stuck "Updating status".
它卡在“更新状态”。 None of the buttons works.
所有按钮都不起作用。
try replacing --onefile
with --onedir
:尝试用
--onefile
替换--onedir
:
pyinstaller.exe --onedir --windowed --icon=app.ico BootcampManager.py
if that doesnt work, then try converting from .py
to .pyw
and get rid of --windowed
如果这不起作用,请尝试从
.py
转换为.pyw
并摆脱--windowed
pyinstaller.exe --onedir --icon=app.ico BootcampManager.pyw
EDIT编辑
from my experience with pyinstaller
, when the exe is behaving "weird"
, its because all the libraries ( DLLs
) are statically linked
into the executable, that is what --onefile
means.根据我对
pyinstaller
的经验,当 exe 表现"weird"
时,这是因为所有库( DLLs
)都statically linked
到可执行文件中,这就是--onefile
含义。
when you link them dynamically
( --onedir
), they are imported at runtime or "when they are imported", so the executable doesnt need to load all the libraries after you open it.当您
dynamically
链接它们时( --onedir
),它们会在运行时或“导入时”导入,因此可执行文件在打开后不需要加载所有库。 meaning that the executable will be faster
and more efficient
.这意味着可执行文件将
faster
、更efficient
。
This may not be the direct answer for OPs issue.这可能不是 OP 问题的直接答案。 But I had the same issue in MacOS.
但我在 MacOS 中遇到了同样的问题。 In my case, I was trying to write a file in the same path as executable.
就我而言,我试图在与可执行文件相同的路径中写入一个文件。
with open("myFile.txt", 'w') as f:
f.write("Some texts")
This works when I run from code, but when I create the executable using pyinstaller --onefile
and executes it, it extracs itself into home folder and try to run inside there, where it doesn't have write access.这在我从代码运行时有效,但是当我使用
pyinstaller --onefile
创建可执行文件并执行它时,它会将自身提取到主文件夹中并尝试在其中运行,但它没有写入权限。 So it fails.所以它失败了。 I couldn't see an error log anywhere as well.
我也看不到任何地方的错误日志。
The solution was to use absolute paths.解决方案是使用绝对路径。
with open("/Users/kmchmk/Documents/myProject/dist/myFile.txt", 'w') as f:
f.write("Some texts")
This issue occured only in MacOS with --onefile
option.此问题仅在具有
--onefile
选项的MacOS中发生。 I've tried Windows and Ubuntu and didn't have any issues.我试过 Windows 和 Ubuntu 没有任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.