python - Pdfkit 操作系统错误 : No wkhtmltopdf executable found

标签 python python-3.x wkhtmltopdf pdfkit

我正在尝试使用 pdfkit 将网页转换为 PDF,但它显示以下错误

Traceback (most recent call last):

  File "<ipython-input-39-33289a2ef087>", line 1, in <module>
runfile('H:/Python/Practice/pdf_read_write.py', wdir='H:/Python/Practice')

  File "C:\Program Files\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)

  File "C:\Program Files\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

  File "H:/Python/Practice/pdf_read_write.py", line 10, in <module>
config = pdfkit.configuration(wkhtmltopdf="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")

  File "C:\Program Files\Anaconda3\lib\site-packages\pdfkit\api.py", line 83, in configuration
return Configuration(**kwargs)

  File "C:\Program Files\Anaconda3\lib\site-packages\pdfkit\configuration.py", line 27, in __init__
'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)

OSError: No wkhtmltopdf executable found: "C:\Program Files\wkhtmltopdin\wkhtmltopdf.exe"
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

我已经从 Here 下载了 wkhtmktopdf并安装。添加了环境变量的路径,但仍然显示相同的错误。
我试过配置 pdfkit 但没有任何效果。

这是我的代码:

import pdfkit
config = pdfkit.configuration(wkhtmltopdf="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe")
pdfkit.from_url("http://www.geeksforgeeks.org/convex-hull-set-2-graham-scan/", "out.pdf",configuration=config)

如何解决这个问题??

最佳答案

您的配置路径包含一个 ASCII Backspace\bin 中的 \b,pdfkit 似乎正在剥离并转换 C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exeC:\Program Files\wkhtmltopdf\wkhtmltopdf.exe

这可以通过使用 r 来解决,这使得它成为 raw literal

config_path = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'

\\

config_path = 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'

关于python - Pdfkit 操作系统错误 : No wkhtmltopdf executable found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42420570/

相关文章:

python - 将 while 循环添加到 try 和 except 语句

python - 使用条件值将列添加到 txt

wkhtmltopdf - 如何获得 wkhtmltopdf 正文中的总页数?

python - 为什么显示退出状态 1?

python - 通过恰好 k 次买卖股票获得最大利润

python - 使用 for 循环的直方图 : Python matplotlib. bar

python 3 如何在上一个输入行上打印

html - WKHTMLTOPDF 从左边距截断文本

c# - 图像未显示在 wkhtmltoxsharp wrapper for wkhtmltopdf 生成的 pdf 中

python - 使用 Selenium Actionchains 时指定 Actions 之间的等待时间