13

I have the following Hello World code to try out TeX rendering with matplotlib on my Mac.

import matplotlib.pyplot as plt
from matplotlib import rc

rc('text', usetex=True)
rc('font', family='serif')

plt.text(2,2,r"Hello World!")
plt.show()

With that code, I'd get the following error:

sh: latex: command not found
Exception in Tkinter callback
<... a long Traceback here ...>
RuntimeError: LaTeX was not able to process the following string:
'lp'
Here is the full report generated by LaTeX:

I don't see any kind of full report after the last line. Anyway, I think this is a path problem. Some pointers on how I could fix it? I have TeX Live 2010.

I tried adding /Library/TeX/Root/bin/universal-darwin to the Global Python Path of the Project Properties, but I still get the same errors. enter image description here

Kit
  • 30,365
  • 39
  • 105
  • 149

1 Answers1

13

In future you might want to mention that you're running the code from NetBeans. The Python path is not $PATH, instead it's sys.path, the path from which Python code is loaded. You need to set os.environ['PATH'] in your Python code; with TeX Live the preferred way to reference the current TeX installation is /usr/texbin.

Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124
  • Right about the NetBeans part. This is my 3rd question on the same topic this week. I thought I already put it in. I also couldn't add `/usr/texbin` which I got from `which latex` on the Terminal. Clicking "Add..." won't let me manually type in a path. Can you give an example of how to use `os.environ`? Its [entry](http://docs.python.org/library/os.html#process-parameters) in the documentation doesn't have a usage example. – Kit May 21 '11 at 14:21
  • os.environ is just a Python dictionary. You can manipulate it like any other. – Nicholas Riley May 21 '11 at 14:55
  • 5
    I got it now. `os.environ['PATH'] = os.environ['PATH'] + ':/usr/texbin'` Thanks! – Kit May 21 '11 at 23:56