neovim / pynvim

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

pip install pynvim fails on macOS M1 trying to build greenlet. #512

Closed 661020786 closed 6 months ago

661020786 commented 1 year ago

pip install pynvim fails trying to build greenlet.o

$ pip install pynvim

Attached is the log. Below is the snippet showing the error

creating build/temp.macosx-11-arm64-cpython-39/src/greenlet clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk -I/opt/homebrew/Cellar/python@3.9/3.9.13_1/envs/neovim/include -I/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/greenlet/greenlet.c -o build/temp.macosx-11-arm64-cpython-39/src/greenlet/greenlet.o dyld: Library not loaded: @rpath/libclang-cpp.dylib Referenced from: /opt/homebrew/bin/clang Reason: image not found error: command '/opt/homebrew/bin/clang' failed with exit code -6 [end of output] [log-install-pynvim.txt](https://github.com/neovim/pynvim/files/9247809/log-install-pynvim.txt)

Shougo commented 1 year ago

It is not pynvim issue.

https://github.com/neovim/pynvim/issues/502

wookayin commented 1 year ago

On a M1 mac, one should use the following command to workaround the issue:

pip install --no-binary greenlet pynvim

See also #473

sidequestboy commented 1 year ago

I'm getting a similar error on my M1 Pro Macbook Pro:

stderr: Traceback (most recent call last):  File "<string>", line 1, in <module>  File "/Users/jamie/opt/anaconda3/lib/python3.9/site-packages/neovim/__init__.py", line 5, in <module>    import pynvim  File "/Users/jamie/opt/anaconda3/lib/python3.9/site-packages/pynvim/__init__.py", line 11, in <module>    from pynvim.msgpack_rpc import (ErrorResponse, child_session, socket_session,  File "/Users/jamie/opt/anaconda3/lib/python3.9/site-packages/pynvim/msgpack_rpc/__init__.py", line 10, in <module>    from pynvim.msgpack_rpc.session import ErrorResponse, Session  File "/Users/jamie/opt/anaconda3/lib/python3.9/site-packages/pynvim/msgpack_rpc/session.py", line 7, in <module>    import greenlet  File "/Users/jamie/opt/anaconda3/lib/python3.9/site-packages/greenlet/__init__.py", line 29, in <module>    from ._greenlet import _C_API # pylint:disable=no-name-in-moduleImportError: dlopen(/Users/jamie/opt/anaconda3/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '__ZSt20__throw_length_errorPKc'

when I check the file type of _greenlet.cpython-39-darwin.so, I get:

$ file ~/opt/anaconda3/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so
/Users/jamie/opt/anaconda3/lib/python3.9/site-packages/greenlet/_greenlet.cpython-39-darwin.so: Mach-O 64-bit bundle arm64

which indicates to me that greenlet is compiled for arm64

I have tried different python versions (3.8, 3.9, 3.11) with the same result

I have tried uninstalling and reinstalling pynvim and greenlet using the command

pip uninstall pynvim greenlet
pip install --no-cache-dir --no-binary greenlet pynvim

but the problem persists for me. I am running up-to-date macos 13.2, with xcode commandline developer tools installed.

I am managing my python version using Anaconda, and I have neovim installed via homebrew.

nvim --version
NVIM v0.8.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Ventura-arm64.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.2/share/nvim"

Run :checkhealth for more info
pip show greenlet
Name: greenlet
Version: 2.0.1
Summary: Lightweight in-process concurrent programming
Home-page: https://greenlet.readthedocs.io/
Author: Alexey Borzenkov
Author-email: snaury@gmail.com
License: MIT License
Location: /Users/jamie/opt/anaconda3/lib/python3.9/site-packages
Requires:
Required-by: pynvim
pip show pynvim
Name: pynvim
Version: 0.4.3
Summary: Python client to neovim
Home-page: http://github.com/neovim/pynvim
Author: Thiago de Arruda
Author-email: tpadilha84@gmail.com
License: Apache
Location: /Users/jamie/opt/anaconda3/lib/python3.9/site-packages
Requires: greenlet, msgpack
Required-by:

I have also tried setting let g:python3_host_prog = '/Users/jamie/opt/anaconda3/bin/python' with the same result.

The error comes up also when I open an python REPL and type import pynvim.

Does anybody have an idea to point me in the right direction?

sidequestboy commented 1 year ago

I resolved my issue by ensuring msgpack and greenlet and pip were installed through anaconda. This was by:

pip uninstall msgpack greenlet pynvim
conda install pip
Collecting package metadata (current_repodata.json): done
Solving environment: /
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - defaults/osx-arm64::dask==2022.7.0=py39hca03da5_0
  - defaults/osx-arm64::distributed==2022.7.0=py39hca03da5_0
  - defaults/osx-arm64::anaconda==2022.10=py39_0
  - defaults/noarch::intake==0.6.5=pyhd3eb1b0_0
  - defaults/osx-arm64::sqlalchemy==1.4.39=py39h1a28f6b_0
  - defaults/osx-arm64::datashader==0.14.1=py39hca03da5_0
done

## Package Plan ##

  environment location: /Users/jamie/opt/anaconda3

  added / updated specs:
    - pip

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _anaconda_depends-2022.10  |           py39_2          69 KB
    anaconda-custom            |           py39_1           3 KB
    certifi-2022.12.7          |   py39hca03da5_0         151 KB
    greenlet-2.0.1             |   py39h313beb8_0         182 KB
    pip-22.3.1                 |   py39hca03da5_0         2.7 MB
    ------------------------------------------------------------
                                           Total:         3.1 MB

The following NEW packages will be INSTALLED:

  _anaconda_depends  pkgs/main/osx-arm64::_anaconda_depends-2022.10-py39_2
  greenlet           pkgs/main/osx-arm64::greenlet-2.0.1-py39h313beb8_0
  msgpack-python     pkgs/main/osx-arm64::msgpack-python-1.0.3-py39h525c30c_0

The following packages will be UPDATED:

  ca-certificates                     2022.07.19-hca03da5_0 --> 2023.01.10-hca03da5_0
  certifi                          2022.9.24-py39hca03da5_0 --> 2022.12.7-py39hca03da5_0
  openssl                                 1.1.1q-h1a28f6b_0 --> 1.1.1s-h1a28f6b_0
  pip                                 22.2.2-py39hca03da5_0 --> 22.3.1-py39hca03da5_0

The following packages will be DOWNGRADED:

  anaconda                                   2022.10-py39_0 --> custom-py39_1

Proceed ([y]/n)? y

It seems my issue has to do with ensuring that the compiler is the same between packages, and I guess python itself as well.

This stack overflow post helped put me in the right direction: https://stackoverflow.com/questions/35006614/what-does-symbol-not-found-expected-in-flat-namespace-actually-mean

wookayin commented 6 months ago

With greenlet 3.0+, all supported pythons have universal (x86_64 + arm64) wheel files, so we can close this now.