使用Pyinstaller添加外部EXE文件
我有一个Python程序,该程序使用多个文件,包括 .exe
program,with subprocess.run(myProgram.exe)
。 /代码>带有 pyinstaller
并尝试执行程序,它找不到 myProgram.exe
。
我正在使用以下语句:
pyinstaller -w -F --onefile .\MyPythonProgram.py
myProgram.exe
在与 mypythonprogram.py
的同一文件夹中。我应该更改任何内容以将其添加到 .exe
中吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在回答之前,由于与版权,专利,法律等有关的影响,将可执行文件捆绑到您的程序中时要保持警惕。我知道OP的问题是针对他们自己的
.exe .exe
,但是此消息适用于其他阅读这篇文章的人。不要问我这个问题,我不是律师。,除非您将
.exe
复制到目标环境中,否则必须将其包括在其中一个参数中pyinstaller
。 Pyinstaller很棒,但是它并不像您想象的那样聪明(例如,它不会扫描您的代码以供次级过程,并自动尝试找到可执行的依赖项)。相反,您必须明确告诉它包括外部依赖项:
下次,尝试阅读其 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 topyinstaller
. 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:
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