RuntimeError: latex program is not installed

2.8k views Asked by At

I am trying to display LaTex. I want to create a python project with Tkinter where the user enters an equation and receives a solution. For this I'm trying to learn how to use LaTex.

I copied this code from another question on StackOverflow:

import sympy as sp
import tkinter as tk
from io import StringIO, BytesIO
from PIL import Image, ImageTk

x,y = sp.symbols('x,y')
expr = sp.sin(sp.sqrt(x**2 + 20)) + y

f = BytesIO()
sp.preview(expr, viewer='BytesIO', outputbuffer=f)
f.seek(0)
root = tk.Tk()
img = Image.open(f)
pimg = ImageTk.PhotoImage(img)
lbl = tk.Label(image=pimg)
lbl.pack()
root.mainloop()

I downloaded MikTex, but I still receive this error -

RuntimeError: latex program is not installed

I run my code with pycharm. How can I fix this? any ideas ?

1

There are 1 answers

11
scotty3785 On

It seems likely that sympy cannot find the latex executable, this can be confirmed by running

from sympy.utilities.misc import find_executable
find_executable('latex')

If this returns false, the latex isn't on the system path for use by sympy.

You need to add the directory containing latex to the system's path, as this is OS specific, you'll need to let us know which OS you are using. On Windows you would edit the PATH Environment Variable and append the folder name to the end of the current entry (using semi-colons as a separator)