2014-12-28 4 views
6

Ich habe versucht, pdfkit Python API in meinem Windows 8-Rechner zu installieren. Ich bekomme Probleme im Zusammenhang mit dem Pfad.Kann nicht PDF mit Python erstellen PDFKIT Fehler: "Keine wkhtmltopdf ausführbare Datei gefunden:"

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 

Ist jemand installiert Python PDFKIt in Windows-Maschine? Wie man diesen Fehler auflöst.

Mein Beispielcode:

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

Antwort

4

ich heute lernen, Python, und ich traf das gleiche Problem, in letzter Zeit habe ich die Fenster Umgebungsvariablen und alles ist in Ordnung.
Ich füge dem Pfad den Installationspfad von wkhtml hinzu, zum Beispiel: "D: \ developAssistTools \ wkhtmltopdf \ bin;" ist mein Installationspfad von wkhtml, und ich füge es dem Pfad hinzu, alles ist OK.

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

schließlich finde ich ein out.pdf.

8

sollten ohne Änderung der Variablen Windows-Umgebung folgende Arbeiten:

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) 

den Weg ist natürlich richtig Unter der Annahme (zB in meinem Fall ist es R'C: \ Program Files (x86) \ wkhtmltopdf \ bin \ wkhtmltopdf.exe ').

6

Bitte installieren wkhtmltopdf verwenden,

sudo apt-get install wkhtmltopdf 

für Windows-Rechner installieren von unten Link, http://wkhtmltopdf.org/downloads.html

und Sie müssen wkhtmltopdf Pfad in Umgebungsvariablen

+0

Sie müssen es auch zum PATH unter Windows hinzufügen, entsprechend dem Link zum pdfkit-Wiki hier https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf – Max

0

Fand die decode auf einem Fenster hinzufügen Plattform musste eine binäre Zeichenfolge sein, versuchen Sie:

 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) 
-1

Keine Notwendigkeit, wkhtmltopdf Pfad in Code zu schreiben. Definieren Sie einfach eine Umgebungsvariable dafür, und es funktioniert.

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

Für mich funktioniert dieser Code.

1

Sie brauchen gesetzt

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

0

IOError: 'No wkhtmltopdf executable found'

Vergewissern Sie sich, dass Sie wkhtmltopdf in Ihrem $ PATH haben oder eingestellt über benutzerdefinierte Konfiguration. Wo whtmltopdf in Windows oder welche wkhtmltopdf unter Linux sollte tatsächlichen Pfad zu binären zurückgeben.

Add Konfigurationszeile für mich gearbeitet:

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

From github

Scheint Sie configuration=config als Argument übergeben müssen.

0
 
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') 

sehr gute Lösung! danke allen!

Verwandte Themen