sympy-live icon indicating copy to clipboard operation
sympy-live copied to clipboard

LaTeX parser has antlr dependency

Open sidhantnagpal opened this issue 7 years ago • 8 comments

As LaTeX parser requires antlr-python-runtime, the following code block from the docstring throws an error:

    >>> from sympy.parsing.latex import parse_latex  # doctest: +SKIP
    >>> expr = parse_latex(r"\frac {1 + \sqrt {\a}} {\b}")  # doctest: +SKIP
    >>> expr  # doctest: +SKIP
    (sqrt(a) + 1)/b
    >>> expr.evalf(4, subs=dict(a=5, b=2))  # doctest: +SKIP
    1.618

with the following traceback:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/56.412575950366508090/sympy/sympy/parsing/latex/__init__.py", line 31, in parse_latex
    return _latex.parse_latex(s)
  File "/base/data/home/apps/s~sympy-live-hrd/56.412575950366508090/sympy/sympy/parsing/latex/_parse_latex_antlr.py", line 66, in parse_latex
    raise ImportError("LaTeX parsing requires the antlr4 python package,"
ImportError: LaTeX parsing requires the antlr4 python package, provided by pip (antlr4-python2-runtime or antlr4-python3-runtime) or conda (antlr-python-runtime)

sidhantnagpal avatar Oct 18 '18 09:10 sidhantnagpal

Not likely we can do anything about this, at least with the current Live architecture.

asmeurer avatar Oct 18 '18 17:10 asmeurer

I found a solution for this. Doing pip install antlr4-python3-runtime was not working for me, I was getting the same error.

Follow these steps :-

  1. Install antlr4 from https://pypi.python.org/pypi/antlr4-python3-runtime (for python 3) or https://pypi.python.org/pypi/antlr4-python2-runtime ( for python 2).

  2. Extract the zip folder and inside the src folder you will find a folder named "antlr4". Copy that folder and paste that in your virtual-environment --> lib -- > python(2 or 3) --> site-packages.

  3. Run your script again and it'll work fine.

punish4424 avatar Sep 05 '20 12:09 punish4424

I found a solution for this. Doing pip install antlr4-python3-runtime was not working for me, I was getting the same error.

Follow these steps :-

1. Install antlr4 from https://pypi.python.org/pypi/antlr4-python3-runtime (for python 3) or https://pypi.python.org/pypi/antlr4-python2-runtime ( for python 2).

2. Extract the zip folder and inside the src folder you will find a folder named "antlr4". Copy that folder and paste that in your virtual-environment --> lib -- > python(2 or 3) --> site-packages.

3. Run your script again and it'll work fine.

Can you please guide me a little on how to get this set up in a local machine. I don't quite understand which zip folder you are referring to in the second point.

Also, is there any way to do this using a conda installer.

SnoozingSimian avatar Mar 29 '21 07:03 SnoozingSimian

Install an earlier version

pip install antlr4-python3-runtime==4.x.x

csdrli avatar Dec 28 '22 17:12 csdrli

As of 02/2023 you need antlr 4.10 to run parse_latex. See my answer here

fcrozatier avatar Feb 01 '23 18:02 fcrozatier

This is work for me: pip install antlr4-python3-runtime==4.11

Mhieu14 avatar Sep 21 '23 07:09 Mhieu14