无法使用 python PDFKIT 创建 pdf 错误:"未找到 wkhtmltopdf 可执行文件:" [英] Can't create pdf using python PDFKIT Error : " No wkhtmltopdf executable found:"

查看:43
本文介绍了无法使用 python PDFKIT 创建 pdf 错误:"未找到 wkhtmltopdf 可执行文件:"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的 Windows 8 机器上安装 pdfkit Python API.我遇到了与路径相关的问题.

I tried installing pdfkit Python API in my windows 8 machine. I'm getting issues related to path.

Traceback (most recent call last):
  File "C:\Python27\pdfcre", line 13, in <module>
    pdfkit.from_url('http://google.com', 'out.pdf')
  File "C:\Python27\lib\site-packages\pdfkit\api.py", line 22, in from_url
    configuration=configuration)
  File "C:\Python27\lib\site-packages\pdfkit\pdfkit.py", line 38, in __init__
    self.configuration = (Configuration() if configuration is None
  File "C:\Python27\lib\site-packages\pdfkit\configuration.py", line 27, in __init__
    'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
IOError: No wkhtmltopdf executable found: ""
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 机器上安装了 Python PDFKIt 吗?如何解决此错误.

Is anybody installed Python PDFKIt in windows machine? How to resolve this error.

我的示例代码:

import pdfkit
import os
config = pdfkit.configuration(wkhtmltopdf='C:\\Python27\\wkhtmltopdf\bin\\wkhtmltopdf.exe')
pdfkit.from_url('http://google.com', 'out.pdf')

推荐答案

以下应该可以工作而无需修改 windows 环境变量:

The following should work without needing to modify the windows environment variables:

import pdfkit
path_wkhtmltopdf = r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
pdfkit.from_url("http://google.com", "out.pdf", configuration=config)

当然假设路径是正确的(例如,在我的情况下,它是 r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe').

Assuming the path is correct of course (e.g. in my case it is r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe').

这篇关于无法使用 python PDFKIT 创建 pdf 错误:&quot;未找到 wkhtmltopdf 可执行文件:"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆