我想使用pydf在Python 3中生成一个pdf。我在终端(Mac)中测试了它,并收到了下面的错误。,有人知道为什么做什么吗?
如果可能的话,我想坚持使用pydf,而不必迁移到另一个库。
。
我从下载了 wkhtmltopdf版本
以及来自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'
>>>发布于 2021-02-01 18:41:06
这是因为与python-pdf一起打包的二进制文件是用于linux的,不会在MacOS上执行,这在自述文件中作了简要解释。
幸运的是,解决方案很简单,您需要通过自制或类似的方式安装wkhtmltopdf,然后将WKHTMLTOPDF_PATH环境变量设置为指向它。
在我的例子里
export WKHTMLTOPDF_PATH=/usr/local/bin/wkhtmltopdfhttps://stackoverflow.com/questions/60814635
复制相似问题