python gevent 解决 (mach-o file, but is an incompatible architecture (have ‘x86_64‘, need ‘arm64‘))问题

这篇具有很好参考价值的文章主要介绍了python gevent 解决 (mach-o file, but is an incompatible architecture (have ‘x86_64‘, need ‘arm64‘))问题。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

报错

在执行import gevent时出现下面的错误

ImportError: dlopen(/Users/user/data/code/venv/lib/python3.10/site-packages/gevent/_gevent_c_hub_local.cpython-310-darwin.so, 0x0002): tried: '/Users/liam/code/venv/lib/python3.10/site-packages/gevent/_gevent_c_hub_local.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/user/code/venv/lib/python3.10/site-packages/gevent/_gevent_c_hub_local.cpython-310-darwin.so' (no such file), '/Users/user/c'o'd'e/venv/lib/python3.10/site-packages/gevent/_gevent_c_hub_local.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

解决办法

出现该错误是因为我电脑是M1 arm架构的CPU, 需要gevent对arm的支持还有一点问题,有两种解决方式

  • 方式1. 切换M1的终端架构
    在终端执行arch -x86_64 bash可以直接切换到x86_64架构可以解决一些兼容性问题
    user@user ~ % uname -a
    Darwin user 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:52 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8112 arm64
    
    user@user ~ % arch -x86_64 bash
    bash-3.2$ uname -a
    Darwin user 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:52 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8112 x86_64
    
  • 方式2. 源码方式编译安装gevent
    执行arch -arm64 pip3 --no-cache-dir install gevent gevent命令可以通过源码编译方式安装兼容arm架构的gevent

如果安装后出现下面的ValueError: greenlet.greenlet size changed错误, 有可能是greenlet的版本和gevent版本不匹配导致的, gevent似乎因为修某个bug回退了greenlet的版本

ValueError: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 160 from C header, got 40 from PyObject

我的版本如下:

gevent                22.8.0
greenlet              1.1.3

安装gevent的命令可以改成 arch -arm64 pip3 --no-cache-dir pip install greenlet==1.1.3 gevent==22.8.0文章来源地址https://www.toymoban.com/news/detail-401463.html

参考

  1. https://apple.stackexchange.com/questions/436801/m1-mac-mach-o-file-but-is-an-incompatible-architecture-have-x86-64-need-a
  2. https://github.com/gevent/gevent/issues/1923
  3. https://github.com/gevent/gevent/issues/1927
  4. https://github.com/neovim/pynvim/issues/502
  5. https://bugzilla.redhat.com/show_bug.cgi?id=1965584

到了这里,关于python gevent 解决 (mach-o file, but is an incompatible architecture (have ‘x86_64‘, need ‘arm64‘))问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包