[英]OSError: [Errno 8] Exec format error - wkhtmltopdf & pydf
I want to use pydf to generate a pdf in Python 3. I tested it out in terminal (Mac) and received the below error.我想使用 pydf 在 Python 3 中生成 pdf。我在终端(Mac)中对其进行了测试并收到以下错误。 Does anyone know why and what to do?
有谁知道为什么以及该怎么做?
If possible, I would like to stick with pydf and not have to move to another library.如果可能,我想坚持使用 pydf 而不必搬到另一个图书馆。
. .
I downloaded the Mac wkhtmltopdf version from https://wkhtmltopdf.org/downloads.html我从https://wkhtmltopdf.org/downloads.html下载了Mac wkhtmltopdf 版本
As well as pydf from pip install python-pdf
以及来自
pip install python-pdf
pydf
>>> import pydf
>>> pydf.generate_pdf('hello')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pydf/wkhtmltopdf.py", line 145, in generate_pdf
p = _execute_wk(*cmd_args, input=html.encode())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pydf/wkhtmltopdf.py", line 30, in _execute_wk
return subprocess.run(wk_args, input=input, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 453, in run
with Popen(*popenargs, **kwargs) as process:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1499, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pydf/bin/wkhtmltopdf'
>>>
This is because the binary which is packaged with python-pdf
is for linux and will not execute on MacOS, this explained briefly in the README.这是因为用
python-pdf
打包的二进制文件是针对 linux 的,不会在 MacOS 上执行,这在 README 中有简要说明。
Luckily the solution is easy, you need to install wkhtmltopdf via homebrew or similar, then set the WKHTMLTOPDF_PATH
environment variable to point to it.幸运的是,解决方案很简单,您需要通过自制软件或类似软件安装 wkhtmltopdf,然后将
WKHTMLTOPDF_PATH
环境变量设置为指向它。
In my case that's在我的情况下
export WKHTMLTOPDF_PATH=/usr/local/bin/wkhtmltopdf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.