error:No wkhtmltopdf executable ,vscode环境变量配置

2022-08-17 22:34:09 浏览数 (2)

版本&環境:

windows11

Django 4.0

IDE:vscode1.70.1

pdfkit==1.0.0

django-wkhtmltopdf==3.4.0

用途:

将html以pdf形式出力

安装:

wkhtmltopdf

问题:

error message :

代码语言:javascript复制
  File "D:PycharmProjectsenvlibsite-packagespdfkitapi.py", line 72, in from_string
    r = PDFKit(input, 'string', options=options, toc=toc, cover=cover, css=css,
  File "D:PycharmProjectsenvlibsite-packagespdfkitpdfkit.py", line 45, in __init__
    self.configuration = (Configuration() if configuration is None
  File "D:PycharmProjectsenvlibsite-packagespdfkitconfiguration.py", line 38, in __init__
raise IOError('No wkhtmltopdf executable found: "%s"n'
OSError: No wkhtmltopdf executable found: "b''"
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

原因:虚拟环境下,找不到【wkhtmltopdf.exe】执行文件。

解决:配置环境变量

vscode左下角,变更齿轮 > settings > 搜索【env】> terminal 下找到windows

选择【edit in settings.json】

※Mac:terminal.integrated.env.osx

image.pngimage.png

settings.json编辑,若需加多个path,用【;】分号分隔

配置后需要重启虚拟环境,若不行,则重启vscode

代码语言:javascript复制
    "terminal.integrated.env.windows": {
        "path":"D:\Program Files\wkhtmltopdf\bin"
    },

补充

若在vscode终端有其他命令不能执行,也可尝试此方法,配置环境量

#No wkhtmltopdf executable found

0 人点赞