PDFKit FileNotFoundError Python

6.3k views Asked by At

I'm trying to convert a html file to PDF using pdfkit in Python3. I'm using PyCharm with macOS Mojave and this is the error I get when trying to run the code:

   Traceback (most recent call last):
   File "/Users/cesarvargas/miniconda3/envs/test/lib/python3.6/site- 
   packages/pdfkit/configuration.py", line 21, in __init__
   with open(self.wkhtmltopdf) as f:
   FileNotFoundError: [Errno 2] No such file or directory: b''

This is the code that I'm using:

import pdfkit

if __name__ == "__main__":
    with open("test.html") as f:
        t = pdfkit.from_file(f, False)
2

There are 2 answers

0
César Vargas On BEST ANSWER

I already resolved the error, installing the WKHTMLtoPDF binaries:

https://wkhtmltopdf.org/downloads.html

More info here:

https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

0
Raihanul Alam Hridoy On

I was executing it on a windows machine. This is how I solved the problem: Install wkhtmltopdf from this link: https://wkhtmltopdf.org/downloads.html

Add C:\Program Files\wkhtmltopdf\bin to Environment Variables Path.

Restart the terminal. Now it will work.