如何使用pyinstaller在可执行文件中包含.dll文件? [英] How do I include .dll file in executable using pyinstaller?
问题描述
我想从我的python脚本生成一个可执行文件. 为此,我使用pyinstaller.我在mkl库中遇到了问题,因为我在脚本中使用了numpy.
I want to generate a single executable file from my python script. For this I use pyinstaller. I had issues with mkl libraries because I use numpy in the script.
我使用了这个 hook ,所以解决了这个问题,就可以了美好的.但是,如果我将单个可执行文件复制到另一个目录并执行它,将无法正常工作.我想我也必须复制该钩子.但是我只想拥有一个可以在其他计算机上使用的文件,而无需复制.dll's
或挂钩.
I used this hook so solve the issue, it worked fine. But it does not work if I copy the single executable file to another directory and execute it. I guess I have to copy the hook also. But I just want to have one single file that I can use at other computers without copying .dll's
or the hook.
我还按照此处所述更改了.spec
文件,并添加了必要的文件到binaries
变量.只要.dll's
在变量binaries
的提供目录中,该命令也可以使用,但是当我在不具有这些.dll's
的计算机上使用该可执行文件时,该命令将不起作用.
I also changed the .spec
file as described here and added the necessary files to the binaries
-variable. That also works as long as the .dll's
are in the provided directory for the binaries
-variable , but that won't work when I use the executable on a computer that doesn't have these .dll's
.
我尝试使用--hidden-import= FILENAME
选项.这也解决了这个问题,但是只是在某个地方提供了.dll's
时.
I tried using the --hidden-import= FILENAME
option. This also solves the issue, but just when the .dll's
are provided somewhere.
我正在寻找一种将.dll's
捆绑到单个可执行文件中的可能性,这样我就有一个独立工作的文件.
What I'm looking for is a possibility to bundle the .dll's
into the single executable file so that I have one file that works independently.
推荐答案
当我遇到此处所述的问题时 https://github.com/ContinuumIO/anaconda-issues/issues/443 我的解决方法是
When I faced problem described here https://github.com/ContinuumIO/anaconda-issues/issues/443 my workaround was
pyinstaller -F --add-data vcruntime140.dll;. myscript.py
-F
-收集到一个 *.exe 文件
.
-exe文件中dll的目标路径
.
- Destination path of dll in exe file
http://pyinstaller.readthedocs.io/en/stable /spec-files.html#adding-data-files
这篇关于如何使用pyinstaller在可执行文件中包含.dll文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!