3

I have written a python application which makes use of pdfkit package to print PDFs. I am using pyinstaller to build an executable of this application on Ubuntu. pdfkit depends on wkhtmltopdf installed with sudo apt install under /usr/bin/.

As per the pyinstaller documentation binaries can be included by adding each binary to the "binaries" list in the .spec file. However this does not seem to work. I also tried to create a copy of the wkhtmltopdf in the pwd and added the file to the "datas" list in the .spec file but it did not work.

How can I include the wkhtmltopdf binary present under /usr/bin/ to my package so that the end user need not install it separately?

redwine
  • 47
  • 8

1 Answers1

0

pyinstaller version 3.6, Ubuntu 18.04, but it should work with windows as well.

I was able to do it by modifying the .spec file.

To make the spec file:

pyi-makespec your_python_script.py

A file named my_python_script.spec will be created. Open it with a text editor and change line binaries from:

binaries=[],

to

binaries=[('/usr/bin/wkhtmltopdf','.')],

In other words put the path of wkhtmltopdf in the first place of the touple.

Then run the following to make the executable:

pyinstaller your_python_script.spec

---A bit of explaining:

Every element of the list [] is a tuple containing as elements the path to the binary and the relative path to the final executable file.

Charalamm
  • 1,547
  • 1
  • 11
  • 27
  • hello. are you using pandas as well? – Charalamm Oct 01 '20 at 10:07
  • Are you sure `wkhtmltopdf` is the problem? I am not sure that is related but `pandas 1.0.3` seem to have a problem with pyinstaller. [Reference](https://stackoverflow.com/questions/60767017/importerror-dll-load-failed-while-importing-aggregations-the-specified-module/61167241#comment109726352_61167241) – Charalamm Oct 01 '20 at 10:15