我使用pdfkit与jupyter笔记本电脑在windows 10上没有问题。
现在我需要在Google上使用它,甚至不知道从哪里开始。
我尝试将linux包安装到“/user/content”中
! 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)发布于 2022-09-02 12:04:34
#这对我有用
#首先检查您的操作系统
!cat /etc/os-release
#并使用!uname -m检查处理器体系结构
我的是(获取Ubuntu x86_64)
#现在你安装了依赖程序
!pip install pdfkit
!wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
!cp wkhtmltox_0.12.6-1.bionic_amd64.deb /usr/bin
!sudo apt install /usr/bin/wkhtmltox_0.12.6-1.bionic_amd64.deb#pdfkit现在应该起作用了
pdfkit.from_url("test.html", "out.pdf")
来源:How to set wkhtmltoimage path when using imgkit in google colab?
https://stackoverflow.com/questions/68245280
复制相似问题