Search code examples
pythonantlr

Import "antlr4" could not be resolved


I have already install antlr through brew install antlr but i cant import it in my vscode with this error Import "antlr4" could not be resolved How can i solve this problem?

I have tried reinstall the antlr but it didnt work. Thanks for ur help.


Solution

  • Don't use brew to install ANTLR. Whatever comes from brew is most probably old. First do brew uninstall antlr.

    Understand that there are 2 different things you can install through pip (or other non-Python package managers):

    1. the ANTLR runtime, needed to run parser/lexer code that is generated by the ANTLR tool
    2. the ANTLR tool, responsible for converting yout .g4 grammar file into parser/lexer classes (Python code in your case)

    pip3 install antlr4-python3-runtime (obviously) installs only the run-time. If you want to convert a grammar into parser/lexer code, do pip3 install antlr4-tools instead.

    See the official ANTLR getting started guide for more detailed information.

    but it didnt work

    If you still have problems, try updating your question with more detailed information than things like "but it didnt work", which does not help others help you.