iis服务器助手广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python gevent 解决 (mach-o file, but is an incompatible architecture (have ‘x86_64‘, need ‘arm64‘))问题
  • 176
分享到

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

pythonlinuxbasharmM1 2023-09-14 16:09:08 176人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

报错 在执行import gevent时出现下面的错误 ImportError: dlopen(/Users/user/data/code/venv/lib/python3.10/site-packa

报错

在执行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 -aDarwin 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 arm64user@user ~ % arch -x86_64 bashbash-3.2$ uname -aDarwin 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.0greenlet              1.1.3

安装gevent的命令可以改成 arch -arm64 pip3 --no-cache-dir pip install greenlet==1.1.3 gevent==22.8.0

参考

  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

来源地址:https://blog.csdn.net/qq_26545503/article/details/128355046

--结束END--

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

本文链接: https://www.lsjlt.com/news/407509.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作