LaTeX parser has antlr dependency
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)
Not likely we can do anything about this, at least with the current Live architecture.
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 :-
-
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).
-
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.
-
Run your script again and it'll work fine.
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.
Install an earlier version
pip install antlr4-python3-runtime==4.x.x
As of 02/2023 you need antlr 4.10 to run parse_latex.
See my answer here
This is work for me:
pip install antlr4-python3-runtime==4.11