Aru*_*ash 20 python api pdfkit python-2.7
我尝试在我的Windows 8机器上安装pdfkit Python API.我遇到了与路径有关的问题.
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
Run Code Online (Sandbox Code Playgroud)
是否有人在Windows机器上安装了Python PDFKIt?如何解决此错误.
我的示例代码:
import pdfkit
import os
config = pdfkit.configuration(wkhtmltopdf='C:\\Python27\\wkhtmltopdf\bin\\wkhtmltopdf.exe')
pdfkit.from_url('http://google.com', 'out.pdf')
Run Code Online (Sandbox Code Playgroud)
kad*_*dee 24
以下应该可以在不修改Windows环境变量的情况下工作:
import pdfkit
path_wkhtmltopdf = r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
pdfkit.from_url("http://google.com", "out.pdf", configuration=config)
Run Code Online (Sandbox Code Playgroud)
假设路径当然是正确的(例如在我的情况下它是r'C:\ Program Files(x86)\ wkhtmltopdf\bin\wkhtmltopdf.exe').
Moh*_*med 10
请使用安装wkhtmltopdf,
sudo apt install -y wkhtmltopdf
Run Code Online (Sandbox Code Playgroud)
对于Windows机器从下面链接安装它,http://wkhtmltopdf.org/downloads.html
并且您需要将wkhtmltopdf路径添加到环境变量中
IOError: 'No wkhtmltopdf executable found'
确保$ PATH中包含wkhtmltopdf或通过自定义配置进行设置。where wkhtmltopdf在Windows或which wkhtmltopdfLinux上,应返回二进制的实际路径。
添加此配置行对我有用:
config = pdfkit.configuration(wkhtmltopdf="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe")
pdfkit.from_string(html, 'MyPDF.pdf', configuration=config)
Run Code Online (Sandbox Code Playgroud)
似乎您需要configuration=config作为参数传递。
我今天正在学习python,我遇到了同样的问题,最近我设置了windows环境变量,一切都还可以.
我将wkhtml的安装路径添加到路径中,例如:"D:\ developAssistTools\wkhtmltopdf\bin;" 是我的wkhtml的安装路径,我把它添加到路径,一切都OK.
import pdfkit
pdfkit.from_url("http://google.com", "out.pdf")
Run Code Online (Sandbox Code Playgroud)
最后,我发现了一个out.pdf.
| 归档时间: |
|
| 查看次数: |
34834 次 |
| 最近记录: |