neovim / pynvim

Python client and plugin host for Nvim
http://pynvim.readthedocs.io/en/latest/
Apache License 2.0
1.51k stars 118 forks source link

ImportError for pynvim / greenlet: arm64 (M1) support for python-neovim #473

Closed wookayin closed 3 years ago

wookayin commented 3 years ago

I have python3 and neovim running on arm64 (M1 mac), but python3 host cannot be loaded because greenlet crashes.

❯❯❯ file $(which python3)
/opt/homebrew/bin/python3: Mach-O 64-bit executable arm64

❯❯❯ file $(which nvim)  
/opt/homebrew/bin/nvim: Mach-O 64-bit executable arm64

Python import:

>>> import pynvim
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "$HOME/Library/Python/3.9/lib/python/site-packages/pynvim/__init__.py", line 11, in <module>
    from pynvim.msgpack_rpc import (ErrorResponse, child_session, socket_session,
  File "$HOME/Library/Python/3.9/lib/python/site-packages/pynvim/msgpack_rpc/__init__.py", line 10, in <module>
    from pynvim.msgpack_rpc.session import ErrorResponse, Session
  File "$HOME/Library/Python/3.9/lib/python/site-packages/pynvim/msgpack_rpc/session.py", line 7, in <module>
    import greenlet
ImportError: dlopen($HOME/Library/Python/3.9/lib/python/site-packages/greenlet.cpython-39-darwin.so, 2): no suitable image found.  Did find:
        $HOME/Library/Python/3.9/lib/python/site-packages/greenlet.cpython-39-darwin.so: mach-o, but wrong architecture
        $HOME/Library/Python/3.9/lib/python/site-packages/greenlet.cpython-39-darwin.so: mach-o, but wrong architecture

Possibly related to #463, but this is a different (new) one because this is with regard to M1/arm64 support.

This is because when one installs greenlet via pip, a wrong architecture wheel would get installed.

Workaround

Install greenlet, forcing to be installed from source.

pip uninstall greenlet
pip install -I greenlet --no-binary greenlet
wookayin commented 3 years ago

Turns out it was because of a wrong wheel cached (perhaps had generated by non-arm64 python). Closing the issue as normal uses is less likely to experience this issue as long as they are doing clean installations.

wookayin commented 2 years ago

Upstream issue: https://github.com/python-greenlet/greenlet/issues/234

wookayin commented 1 year ago

greenlet 2.0 is out, and it seems we do not need --no-binary any more. (The shared library can be installed as arm64).