首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pdfkit OSError:找不到wkhtmltopdf可执行文件

Pdfkit OSError:找不到wkhtmltopdf可执行文件
EN

Stack Overflow用户
提问于 2017-02-23 23:58:52
回答 1查看 12.8K关注 0票数 7

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

代码语言:javascript
复制
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,但都不起作用。

下面是我的代码:

代码语言:javascript
复制
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)

如何解决这个问题??

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-24 00:13:51

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

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

代码语言:javascript
复制
config_path = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'

\\

代码语言:javascript
复制
config_path = 'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42420570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档