【问题标题】:Pdfkit OSError: No wkhtmltopdf executable foundPdfkit OSError:找不到 wkhtmltopdf 可执行文件
【发布时间】:2017-07-14 05:15:15
【问题描述】:

我正在尝试使用 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)

如何解决这个问题??

【问题讨论】:

  • \bin 中的\bASCII Backspace。试试r"C:\Program Files\...""C:\\Program Files\\..."
  • 哦!多谢 !!有效 !! :D 将其发布为答案。 @Wondercricket

标签: python python-3.x wkhtmltopdf pdfkit


【解决方案1】:

您的配置路径包含一个ASCII Backspace\bin 中的\b,pdfkit 似乎正在剥离并将C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe 转换为C:\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'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-02
    • 2017-05-07
    • 2015-02-24
    • 2020-11-05
    • 2015-01-22
    • 2016-04-15
    • 1970-01-01
    • 2019-11-28
    相关资源
    最近更新 更多