2

我在 Windows 10 上使用带有 jupyter notebook 的 pdfkit 没有问题。

现在我需要在 Google Colab 上使用它,甚至不知道从哪里开始。

我尝试将 linux 软件包安装到“/users/contents”中

! wget "https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-3/wkhtmltox-0.12.6-3.archlinux-x86_64.pkg.tar.xz" && \
tar vxfJ "wkhtmltox-0.12.6-3.archlinux-x86_64.pkg.tar.xz" && \
mv wkhtmltox/bin/wkhtmltopdf /usr/bin/wkhtmltopdf

它安装正确。

我试图让 pdfkit 指向路径“/content/usr/bin/wkhtmltopdf”,但没有奏效。

!pip install pdfkit
import pdfkit
path_wkhtmltopdf = "/content/usr/bin/wkhtmltopdf"
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
pdfkit.from_url("test.html", "out.pdf", configuration=config)

返回的错误:

Collecting pdfkit
  Downloading https://files.pythonhosted.org/packages/57/da/48fdd627794cde49f4ee7854d219f3a65714069b722b8d0e3599cd066185/pdfkit-0.6.1-py3-none-any.whl
Installing collected packages: pdfkit
Successfully installed pdfkit-0.6.1
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-9-b691bc3e9060> in <module>()
      3 path_wkhtmltopdf = "/content/usr/bin/wkhtmltopdf"
      4 config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
----> 5 pdfkit.from_url("yggtorrent1.html", "out.pdf", configuration=config)

1 frames
/usr/local/lib/python3.7/dist-packages/pdfkit/pdfkit.py in to_pdf(self, path)
    157 
    158         if exit_code != 0:
--> 159             raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, stderr))
    160 
    161         # Since wkhtmltopdf sends its output to stderr we will capture it

OSError: wkhtmltopdf exited with non-zero code 1. error:
/content/usr/bin/wkhtmltopdf: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /content/usr/bin/wkhtmltopdf)
/content/usr/bin/wkhtmltopdf: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /content/usr/bin/wkhtmltopdf)
4

0 回答 0