使用Pyinstaller添加外部EXE文件

发布于 2025-01-30 05:49:47 字数 404 浏览 2 评论 0 原文

我有一个Python程序,该程序使用多个文件,包括 .exe program,with subprocess.run(myProgram.exe)

。 /代码>带有 pyinstaller 并尝试执行程序,它找不到 myProgram.exe

我正在使用以下语句:

pyinstaller -w -F --onefile .\MyPythonProgram.py

myProgram.exe 在与 mypythonprogram.py 的同一文件夹中。我应该更改任何内容以将其添加到 .exe 中吗?

I have a python program that uses multiple files including an .exe program called with subprocess.run(myprogram.exe).

When I build the new .exe with pyinstaller and try to execute the program, it cannot find myprogram.exe.

I'm using the following statment:

pyinstaller -w -F --onefile .\MyPythonProgram.py

myprogram.exe is in the same folder as MyPythonProgram.py. Should I change anything for it to add it to the .exe?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一瞬间的火花 2025-02-06 05:49:47

在回答之前,由于与版权,专利,法律等有关的影响,将可执行文件捆绑到您的程序中时要保持警惕。我知道OP的问题是针对他们自己的 .exe .exe ,但是此消息适用于其他阅读这篇文章的人。不要问我这个问题,我不是律师。


,除非您将 .exe 复制到目标环境中,否则必须将其包括在其中一个参数中 pyinstaller 。 Pyinstaller很棒,但是它并不像您想象的那样聪明(例如,它不会扫描您的代码以供次级过程,并自动尝试找到可执行的依赖项)。

相反,您必须明确告诉它包括外部依赖项:

pyinstaller.exe --add-binary ".\myprogram.exe;." --onefile .\MyPythonProgram.py

下次,尝试阅读其 docs a>因为您使用的是 -f - OneFile (他们都做同样的事情)。

github问题帮助我回答了您的问题。它解释了为什么 - add-binary 的arg在引号中以及对;。零件的需求。

注意:我已经排除了您的 -w 清洁答案的选项

Before I answer, be wary when bundling executables into your programs because of implications related to copyrights, patents, legal, etc. I know the OP's question is for their own .exe, but this message is for other people reading this post. Don't ask me about this, I am not a lawyer.


Unless you copy your .exe over to your target environment, you have to include it in one of the arguments to pyinstaller. PyInstaller is great, but it isn't as smart as you're imagining it to be (e.g. it doesn't scan your code for calls to subprocess and automatically try and find your executable dependencies).

Instead, you have to explicitly tell it to include external dependencies:

pyinstaller.exe --add-binary ".\myprogram.exe;." --onefile .\MyPythonProgram.py

Next time, try reading their docs because you're using -F and --onefile (they both do the same thing).

This GitHub issue helped me answer your question. It explains why --add-binary's arg is in quotes as well as the need for the ;. part at the end.

Note: I've excluded your -w option for a cleaner answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文