tree-sitter-python icon indicating copy to clipboard operation
tree-sitter-python copied to clipboard

feature: pre-compiled binary wheels for M chip macOS (arm64)

Open Co1lin opened this issue 1 year ago • 8 comments

Did you check the tree-sitter docs?

Is your feature request related to a problem? Please describe.

https://github.com/tree-sitter/py-tree-sitter says "Build from source" will be deprecated and in v0.22.0. However, on arm mac, running pip install tree-sitter-python reports "No matching distribution found for tree-sitter-python". I think there is no pre-built wheels for M chip mac.

Describe the solution you'd like

Release the binary for the M chip mac.

Describe alternatives you've considered

/

Additional context

No response

Co1lin avatar Mar 14 '24 14:03 Co1lin

Building from source via tree-sitter is deprecated but you can still build from source via pip.

pip install git+https://github.com/tree-sitter/tree-sitter-python

A macOS arm64 wheel will be available in the next release. Maybe a source distribution as well.

ObserverOfTime avatar Apr 25 '24 15:04 ObserverOfTime

Hello, just checking, could it be possible to get an sdist otherwise ? I assume that would make arm-based fallback to source and build locally ? That's what I've been doing in my pyproject.toml

tree-sitter-python = [
    {platform = "darwin", git="https://github.com/tree-sitter/tree-sitter-python", tag="v0.21.0"},
    {platform = "linux", version="0.21.0"}
]

Gby56 avatar May 22 '24 15:05 Gby56

pip install git+https://github.com/tree-sitter/tree-sitter-python

I tried this and still can't install it. How do I resolve this?

  File "/Users/kiyoon/.config/dotfiles/nvim/find_python_import_in_project.py", line 6, in <module>
    import tree_sitter_python as tspython
  File "/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/__init__.py", line 3, in <module>
    from ._binding import language
ImportError: dlopen(/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/_binding.abi3.so, 0x0002): tried: '/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/_binding.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/_binding.abi3.so' (no such file), '/Users/kiyoon/bin/miniforge3/envs/PPMI/lib/python3.11/site-packages/tree_sitter_python/_binding.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

kiyoon avatar Jun 03 '24 11:06 kiyoon

@kiyoon for intel mac you should be able to pip install tree-sitter normally. Does that not work?

tusharsadhwani avatar Jun 03 '24 11:06 tusharsadhwani

@tusharsadhwani Mine is M1, and it seems like the shared object that is being installed is for intel. pip install tree-sitter-python didn't work for me.

🕙 21:02:13 ❯ pip install tree-sitter-python
ERROR: Could not find a version that satisfies the requirement tree-sitter-python (from versions: none)
ERROR: No matching distribution found for tree-sitter-python

🕙 21:02:15 ✖  uv pip install tree-sitter-python
  × No solution found when resolving dependencies:
  ╰─▶ Because only tree-sitter-python==0.21.0 is available and tree-sitter-python==0.21.0 has no wheels are available with a matching platform, we can conclude that all versions of tree-sitter-python cannot be used.
      And because you require tree-sitter-python, we can conclude that the requirements are unsatisfiable.

kiyoon avatar Jun 03 '24 12:06 kiyoon

I tried this and still can't install it. How do I resolve this?

Something is using the wrong architecture. Could be python, pip, conda, or your compiler.

ObserverOfTime avatar Jun 03 '24 21:06 ObserverOfTime

I think it's my compiler because I had similar problem with rust. But I don't know how to fix it..

kiyoon avatar Jun 03 '24 23:06 kiyoon

I temporarily forked the repo and modified the CI to publish the wheel files on the Release page. I don't know what's wrong with my compiler, but this worked for me.

https://github.com/kiyoon/tree-sitter-python/releases

kiyoon avatar Jun 04 '24 01:06 kiyoon

The wheel is included in 0.23.0

ObserverOfTime avatar Aug 27 '24 15:08 ObserverOfTime

After having successfully installed 0.23.0 in a M chip MacOS, I'm getting this error:

import tree_sitter_python as tspython
from tree_sitter import Language, Parser, Point, Tree

PY_LANGUAGE = Language(tspython.language())

Error:

PY_LANGUAGE = Language(tspython.language())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: an integer is required

ERROR: an integer is required

Any clue why is this happening? With a previous installation of this dependency using git protocol I didn't get this error:

tree-sitter-python @ git+https://github.com/tree-sitter/tree-sitter-python@71778c2a472ed00a64abf4219544edbf8e4b86d7

perseoGI avatar Aug 27 '24 15:08 perseoGI

@perseoGI #280 was opened on that issue. For some reason the issue is closed even though it has not been resolved yet.

ericwb avatar Aug 27 '24 15:08 ericwb

@perseoGI #280 was opened on that issue. For some reason the issue is closed even though it has not been resolved yet.

Did you find a good approach to use python-tree-sitter with python grammar which does not involve using git protocol?

perseoGI avatar Aug 27 '24 16:08 perseoGI

Unfortunately, no. I'm still waiting for all these bugs to get straightened out.

ericwb avatar Aug 27 '24 16:08 ericwb

You need tree-sitter==0.23.0

ObserverOfTime avatar Aug 27 '24 17:08 ObserverOfTime

@ObserverOfTime The bug persists in version 0.23.

jiezhuzzz avatar Aug 28 '24 04:08 jiezhuzzz

It finally works in my setup using this tree-sitter related requirements:

lsp-tree-sitter==0.0.15
tree-sitter==0.23.0
tree-sitter-python==0.23.0

I had to adjust some query.matches results due to some breaking change were introduced on the API in the latest tree-sitter relese. Thank you!

perseoGI avatar Aug 28 '24 08:08 perseoGI