报错
在执行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的支持还有一点问题,有两种解决方式
如果安装后出现下面的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://apple.stackexchange.com/questions/436801/m1-mac-mach-o-file-but-is-an-incompatible-architecture-have-x86-64-need-a
- https://github.com/gevent/gevent/issues/1923
- https://github.com/gevent/gevent/issues/1927
- https://github.com/neovim/pynvim/issues/502
- https://bugzilla.redhat.com/show_bug.cgi?id=1965584
|