tree-sitter / py-tree-sitter

Python bindings to the Tree-sitter parsing library
https://tree-sitter.github.io/py-tree-sitter/
MIT License
817 stars 96 forks source link

Intro code in the README does not run on Python 3.10 and 3.12 #266

Closed lmmx closed 1 month ago

lmmx commented 1 month ago

I've tried this on Python 3.12 and 3.10, and confirmed tree-sitter and tree-sitter-python are installed.

I'm confused as to how something as fundamental as the README example can fail to work.

(tsutil) louis 🚶 ~/dev/tsutil-py $ pip install tree-sitter tree-sitter-python
Requirement already satisfied: tree-sitter in /home/louis/miniconda3/envs/tsutil/lib/python3.10/site-packages (0.20.1)
Requirement already satisfied: tree-sitter-python in /home/louis/miniconda3/envs/tsutil/lib/python3.10/site-packages (0.21.0)

(tsutil) louis 🚶 ~/dev/tsutil-py $ python
Python 3.10.0 (default, Mar  3 2022, 09:58:08) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tree_sitter_python as tspython
>>> from tree_sitter import Language, Parser
>>> PY_LANGUAGE = Language(tspython.language())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Language.__init__() missing 1 required positional argument: 'name'

3.9 and 3.11

It only seems to work on Python 3.9 and 3.11

(tsutil) louis 🚶 ~/dev/tsutil-py $ python
Python 3.9.0 (default, Nov 15 2020, 14:28:56)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tree_sitter_python as tspython
>>> from tree_sitter import Language, Parser
>>> PY_LANGUAGE = Language(tspython.language())
(tsutil) louis 🚶 ~/dev/tsutil-py $ python
Python 3.11.0 (main, Mar  1 2023, 18:26:19) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from tree_sitter import Language, Parser
>>> import tree_sitter_python as tspython
>>> PY_LANGUAGE = Language(tspython.language())

Not clear what is happening under the hood here to cause this 🤔

Edit something weird appears to be going on, I'm now getting an error to even load that when it previously worked

(tsutil) louis 🚶 ~/dev/tsutil-py $ python
Python 3.11.0 (main, Mar  1 2023, 18:26:19) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tree_sitter_python as tspython
>>> from tree_sitter import Language, Parser
>>> PY_LANGUAGE = Language(tspython.language())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Language.__init__() missing 1 required positional argument: 'name'
susnato commented 1 month ago

Hey @lmmx , I use Python 3.10.14 and I can run the example in the README.

Could you please check the installed tree sitter vesrion?

pip freeze | grep tree-sitter

If it shows anything except tree-sitter==0.22.3, then you might need to install the latest version by pip install -U tree-sitter

lmmx commented 1 month ago

Ahhh, I'm sorry that's right, this isn't a Python version it's a py-tree-sitter version. My package manager was for some reason not installing the latest version of tree-sitter. Working perfectly now, false alarm