IOError: No wkhtmltopdf executable found: ""

本文介绍了在使用Python的pdfkit模块时遇到IOError的问题及其解决方案。主要原因是缺少wkhtmltopdf可执行文件,文中提供了下载及配置wkhtmltopdf的方法。

IOError: No wkhtmltopdf executable found: “”

python使用pdfkit中,如果使用pdfkit.from_url 或者pdfkit.from_string等,就会出现上述错误。而且如果你使用pip安装了 wkhtmltopdf,还是会出现这个问题:
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

因此需要去安装windows版本的wkhtmltopdf
此处进入下载网址
安装完成之后需要在代码中添加以下内容:

path_wk = r'C:\Python27\wkhtmltopdf\bin\wkhtmltopdf.exe' #安装位置
config = pdfkit.configuration(wkhtmltopdf = path_wk)
pdfkit.from_url(url, r'D:\are you coding\pdf\taobao.pdf', configuration=config)

如此即可实现了

Traceback (most recent call last): File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\site-packages\pdfkit\configuration.py", line 35, in __init__ with open(self.wkhtmltopdf) as f: FileNotFoundError: [Errno 2] No such file or directory: 'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\PyCharm\pythonProject1031\出账程序\缴费通知单-康桥漕河泾2.py", line 173, in <module> create_bill_pdf(bill_df.sort_values("计量点名称"), tax_rate=0.13) File "E:\PyCharm\pythonProject1031\出账程序\缴费通知单-康桥漕河泾2.py", line 168, in create_bill_pdf html_to_pdf("bill_{}.html".format(sn), File "E:\PyCharm\pythonProject1031\出账程序\utils.py", line 39, in html_to_pdf wkhtmltopdf_config = pdfkit.configuration(wkhtmltopdf=wkhtmltopdf_exe_path) File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\site-packages\pdfkit\api.py", line 86, in configuration return Configuration(**kwargs) File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\site-packages\pdfkit\configuration.py", line 38, in __init__ raise IOError('No wkhtmltopdf executable found: "%s"\n' OSError: No wkhtmltopdf executable found: "C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe" If this file exists please check that this process can read it or you can pass path to it manually in method call, check README. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
最新发布
06-21
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值