gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:48:03 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com