[Errno 86] Bad CPU type in executable: ‘/usr/local/bin/wkhtmltopdf‘

错误原因

[Errno 86] Bad CPU type in executable 表示你的Mac上安装的 wkhtmltopdf 二进制文件与你的CPU架构不匹配。

常见情况

  1. Apple Silicon Mac (M1/M2/M3):安装了为Intel x86_64架构编译的wkhtmltopdf
  2. Intel Mac:安装了为Apple Silicon (ARM64)架构编译的wkhtmltopdf
  3. 错误安装:可能安装了Linux版本的二进制文件

解决方案

1. 重新安装正确架构的wkhtmltopdf

使用Homebrew安装(推荐):

# 卸载现有版本
brew uninstall wkhtmltopdf

# 重新安装
brew install wkhtmltopdf

手动下载:

  • 访问 wkhtmltopdf官网
  • 下载适合你Mac架构的版本:
    • Apple Silicon (M1/M2/M3):选择 ARM64/AArch64 版本
    • Intel Mac:选择 x86_64 版本

2. 检查你的Mac架构

# 查看CPU架构
uname -m
# 或者
arch

3. 验证安装

# 检查wkhtmltopdf位置和架构
which wkhtmltopdf
file /usr/local/bin/wkhtmltopdf

# 测试是否能正常运行
wkhtmltopdf --version

4. 如果使用Python pdfkit库

确保重新安装wkhtmltopdf后,你的Python代码应该能正常工作:

import pdfkit

# 测试
pdfkit.from_string('Hello World!', 'test.pdf')

为什么Ubuntu能运行?

Ubuntu和Mac使用不同的操作系统和架构,Ubuntu上安装的是为Linux x86_64编译的版本,而Mac需要为macOS编译的版本。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MonkeyKing.sun

对你有帮助的话,可以打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值