Cannot create pdf using python. PDFKIT error: "No wkhtmltopdf executable:

I tried installing the pdfkit Python API on my windows 8 machine. I am getting path related problems.

Traceback (most recent call last): File "C:\Python27\pdfcre", line 13, in <module> pdfkit.from_url('http://google.com', 'out.pdf') File "C:\Python27\lib\site-packages\pdfkit\api.py", line 22, in from_url configuration=configuration) File "C:\Python27\lib\site-packages\pdfkit\pdfkit.py", line 38, in __init__ self.configuration = (Configuration() if configuration is None File "C:\Python27\lib\site-packages\pdfkit\configuration.py", line 27, in __init__ 'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf) IOError: No wkhtmltopdf executable found: "" If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf 

Has anyone installed Python PDFKIt on a Windows machine? How to fix this error.

My sample code is:

 import pdfkit import os config = pdfkit.configuration(wkhtmltopdf='C:\\Python27\\wkhtmltopdf\bin\\wkhtmltopdf.exe') pdfkit.from_url('http://google.com', 'out.pdf') 
+18
source share
9 answers

The following should work without changing Windows environment variables:

 import pdfkit path_wkthmltopdf = r'C:\Python27\wkhtmltopdf\bin\wkhtmltopdf.exe' config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf) pdfkit.from_url("http://google.com", "out.pdf", configuration=config) 

Assuming the path is of course correct (for example, in my case it is r'C: \ Program Files (x86) \ wkhtmltopdf \ bin \ wkhtmltopdf.exe ').

+19
source

Please install wkhtmltopdf using

 sudo apt install -y wkhtmltopdf 

for Windows Machine, install it from the link below, http://wkhtmltopdf.org/downloads.html

and you need to add the wkhtmltopdf path to environment variables

+10
source

IOError: 'No wkhtmltopdf executable found'

Make sure you have wkhtmltopdf in your $ PATH or configured through user configuration. where wkhtmltopdf on Windows or which wkhtmltopdf on Linux should return the actual path to the binary.

Adding this configuration line worked for me:

 config = pdfkit.configuration(wkhtmltopdf="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe") pdfkit.from_string(html, 'MyPDF.pdf', configuration=config) 

From github

It seems you need to pass configuration=config as an argument.

+6
source

I am learning python today and I met the same problem, lately I am setting windows environment variables and everything is fine.
I add the wkhtml installation path to the path, for example: "D: \ developAssistTools \ wkhtmltopdf \ bin;" this is my wkhtml installation path, and I add it to the path, everything is fine.

 import pdfkit pdfkit.from_url("http://google.com", "out.pdf") 

Finally, I find out.pdf.

+5
source

You need to install

pdfkit.from_url (' http://google.com ', 'out.pdf', configuration = config)

+1
source

Found that decoding on a Windows platform should be a binary string, try:

  path_wkthmltopdf = b'C:\Program Files\wkhtmltopdf\\bin\wkhtmltopdf.exe' config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf) pdfkit.from_url(url=urlpath, output_path=pdffilepath,configuration=config) 
0
source
  def urltopdf (url, pdffile):
     import pdfkit
     '' '
         input
         - url: target url
         - pdffile: target pdf file name
     '' '
     path_wkthmltopdf = 'D: \\ Program Files (x86) \\ wkhtmltopdf \\ bin \\ wkhtmltopdf.exe'
     config = pdfkit.configuration (wkhtmltopdf = path_wkthmltopdf)
     # pdfkit.from_url (url = urlpath, output_path = pdffilepath, configuration = config)
     pdfkit.from_url (url, pdffile, configuration = config)


 urltopdf ('http: //www.google.com','pdf/google.pdf')

very good solution! thanks everyone!

0
source

When I tried all of the above methods, I encountered a permission error, since I do not have administrator rights on my workstation. If this is the case for you, be sure to install wkhtmltopdf.exe when installing. The destination folder for installation is located in the python site-packages folder or add the directory to sys.path. It is usually installed in the Program Files folder. I changed the installation directory and this works for me:

 import pdfkit pdfkit.from_url("http://google.com", "out.pdf") 
0
source

No need to write wkhtmltopdf path to code. Just define an environment variable for it, and it works.

 import pdfkit pdfkit.from_url('http://google.com', 'out.pdf') 

For me, this code works.

-1
source

Source: https://habr.com/ru/post/980223/


All Articles