1

我试图在 google colab 中使用 imgkit 将 html 文件保存为图像。我很难让它工作。

!pip install imgkit
!pip install wkhtmltopdf

import imgkit 
imgkit.from_file('file.html', 'out.jpg')

错误:

No wkhtmltoimage executable found: "command not found"
If this file exists please check that this process can read it.
Otherwise please install wkhtmltopdf - http://wkhtmltopdf.org

我读过我必须手动设置路径,但我无法弄清楚路径是什么。我还没有找到让它在Google Colab中工作的答案

谢谢!

编辑:感谢@user2314737 的回答,我成功了

%%bash
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb

拿到包后,我不得不把它复制到/usr/bin:

!cp wkhtmltox_0.12.6-1.bionic_amd64.deb /usr/bin
!sudo apt install /usr/bin/wkhtmltox_0.12.6-1.bionic_amd64.deb

然后只是:

import imgkit
imgkit.from_file('file.html', 'out.jpg')
4

1 回答 1

1

您需要安装可执行文件。检查您的操作系统

!cat /etc/os-release
# Out:
# NAME="Ubuntu"
# VERSION="18.04.5 LTS (Bionic Beaver)"
# ...

并检查处理器架构!uname -m

(我得到 Ubuntu x86_64)

然后安装可执行文件

%%bash
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
sudo apt install wkhtmltox_0.12.6-1.bionic_amd64.deb

这是所有下载的列表:https ://wkhtmltopdf.org/downloads.html

于 2022-01-28T12:31:33.340 回答