如何使用 pyinstaller 在可执行文件中包含 .dll 文件? [英] How do I include .dll file in executable using pyinstaller?

查看:64
本文介绍了如何使用 pyinstaller 在可执行文件中包含 .dll 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的 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 的 或钩子.

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-variable 提供的目录中,这也有效,但是当我在没有的计算机上使用可执行文件时,这将不起作用没有这些 .dll 的.

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 的 被提供在某处时.

I tried using the --hidden-import= FILENAME option. This also solves the issue, but just when the .dll's are provided somewhere.

我正在寻找的是一种将 .dll 的 捆绑到单个可执行文件中的可能性,以便我拥有一个独立工作的文件.

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 文件

-F - collect into one *.exe file

. - exe文件中dll的目标路径

. - Destination path of dll in exe file

来自文档http://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files

这篇关于如何使用 pyinstaller 在可执行文件中包含 .dll 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆