简体   繁体   English

OSError: [Errno 8] Exec 格式错误 - wkhtmltopdf & pydf

[英]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.

相关问题 os.execv返回OSError:[Errno 8]执行格式错误 - os.execv returns OSError: [Errno 8] Exec format error OSError: [Errno 8] 在 Raspberry Pi 上使用带有 Selenium 和 Linux 的 ChromeDriver 执行格式错误 - OSError: [Errno 8] Exec format error using ChromeDriver with Selenium and Linux on Raspberry Pi Requests-html 导致 OSError: [Errno 8] 调用 html.render() 时执行格式错误 - Requests-html results in OSError: [Errno 8] Exec format error when calling html.render() 在 Raspberry pi 4 上运行 Python3 脚本时如何解决“OSError: [Errno 8] Exec format error”? - How to solve 'OSError: [Errno 8] Exec format error' when running Python3 script on Raspberry pi 4? 无法启动 docker `OSError: [Errno 8] Exec 格式错误:&#39;/usr/local/bin/docker-credential-ecr-login&#39;` - Cant start docker `OSError: [Errno 8] Exec format error: '/usr/local/bin/docker-credential-ecr-login'` 使用Python运行时,烧瓶调试模式给出“ OSError:[Errno 8] Exec格式错误” - Flask debug mode gives an “OSError: [Errno 8] Exec format error” when running using python Moviepy OSError Exec格式错误-缺少Shebang吗? - Moviepy OSError Exec format error - Missing Shebang? pyaudio OSError: [Errno - 9999] 意外的主机错误 - pyaudio OSError: [Errno - 9999] Unanticipated host error Google Colaboratory:OSError:[Errno 5] 输入/输出错误 - Google Colaboratory : OSError: [Errno 5] Input/output error OSError: [Errno 22] 无效参数:Python 错误 - OSError: [Errno 22] Invalid argument: Python Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM