Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include .dll file in executable using pyinstaller?

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.

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.

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.

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

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.

like image 695
David P Avatar asked Aug 05 '16 14:08

David P


People also ask

Can a dll be an executable?

A DLL file is not by it self executable, though it may contain executable code. A DLL (Dynamic-Link Library) contains code, data, resources etc. usable by other programs. You need an EXE file for the operating system to execute code within DLL files, like "RUNDLL.

Does PyInstaller install dependencies?

PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. PyInstaller reads a Python script written by you.

Where do I put Python DLL files?

In the vast majority of cases, the solution is to properly reinstall python. dll on your PC, to the Windows system folder. Alternatively, some programs, notably PC games, require that the DLL file is placed in the game/application installation folder.


2 Answers

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 - collect into one *.exe file

. - Destination path of dll in exe file

from docs http://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files

like image 52
Ilya Davydov Avatar answered Oct 15 '22 19:10

Ilya Davydov


Add the current project folder to Path, then Create EXE using following command:

pyinstaller --add-binary AutoItX3_x64.dll;. program_name.py

Create folder \dist\program_name\autoit\lib in tge current project folder, and paste AutoItX3_x64.dll in it.

like image 24
Suhas Bhagate Avatar answered Oct 15 '22 19:10

Suhas Bhagate