Search code examples
pythonpyx

Python Error w/ Pyx Module Despite Good Code


Im doing some work with pyx, the python module for customizable data graphing and visualizations. The thing is, even copy pasting the most basic graphing code example directly, returns a broken file and an error. Im relatively new to python and I've never seen an error like this before, it's waaaaay over my head. I've run simple canvas draws before and it worked fine. Whats going on here?

Code:

from pyx import *
g = graph.graphxy(width=10,
                  x=graph.axis.linear(min=-2, max=2)
                  )
g.plot(graph.data.function("y(x)=x**2"))
g.writeEPSfile("x") 

Red Error Text:

Traceback (most recent call last):
  File "C:\Users\User\Desktop\test.py", line 9, in <module>
    g.writeEPSfile("x")
  File "C:\Python34\lib\site-packages\pyx\canvas.py", line 50, in wrappedindocument
    return method(d, file, **write_kwargs)
  File "C:\Python34\lib\site-packages\pyx\document.py", line 180, in writeEPSfile
    pswriter.EPSwriter(self, f, **kwargs)
  File "C:\Python34\lib\site-packages\pyx\pswriter.py", line 142, in __init__
    page.processPS(pagefile, self, acontext, registry, pagebbox)
  File "C:\Python34\lib\site-packages\pyx\document.py", line 130, in processPS
    self._process("processPS", *args)
  File "C:\Python34\lib\site-packages\pyx\document.py", line 78, in _process
    bbox.set(self.canvas.bbox()) # this bbox is not accurate
  File "C:\Python34\lib\site-packages\pyx\graph\graph.py", line 181, in bbox
    self.finish()
  File "C:\Python34\lib\site-packages\pyx\graph\graph.py", line 303, in finish
    self.doaxes()
  File "C:\Python34\lib\site-packages\pyx\graph\graph.py", line 580, in doaxes
    self.dolayout()
  File "C:\Python34\lib\site-packages\pyx\graph\graph.py", line 564, in dolayout
    self.doaxiscreate(axisname)
  File "C:\Python34\lib\site-packages\pyx\graph\graph.py", line 240, in doaxiscreate
    self.axes[axisname].create()
  File "C:\Python34\lib\site-packages\pyx\graph\axis\axis.py", line 620, in create
    self.linkedto.docreate()
  File "C:\Python34\lib\site-packages\pyx\graph\axis\axis.py", line 525, in docreate
    self._createfunction(*self._createargs, **self._createkwargs)
  File "C:\Python34\lib\site-packages\pyx\graph\graph.py", line 240, in doaxiscreate
    self.axes[axisname].create()
  File "C:\Python34\lib\site-packages\pyx\graph\axis\axis.py", line 591, in create
    self.canvas = self.axis.create(self.data, self.positioner, self.graphtexrunner, self.errorname)
  File "C:\Python34\lib\site-packages\pyx\graph\axis\axis.py", line 250, in create
    return _regularaxis._create(self, data, positioner, graphtexrunner, self.parter, self.rater, errorname)
  File "C:\Python34\lib\site-packages\pyx\graph\axis\axis.py", line 220, in _create
    variants[0].storedcanvas = layout(variants[0])
  File "C:\Python34\lib\site-packages\pyx\graph\axis\axis.py", line 141, in layout
    self.painter.paint(canvas, data, self, positioner)
  File "C:\Python34\lib\site-packages\pyx\graph\axis\painter.py", line 192, in paint
    t.temp_labelbox = canvas.texrunner.text_pt(t.temp_x_pt, t.temp_y_pt, t.label, labelattrs)
  File "C:\Python34\lib\site-packages\pyx\text.py", line 1408, in wrapped
    return f(self, *args, **kwargs)
  File "C:\Python34\lib\site-packages\pyx\text.py", line 1439, in text_pt
    return self.instance.text_pt(*args, **kwargs)
  File "C:\Python34\lib\site-packages\pyx\text.py", line 1261, in text_pt
    left_pt, right_pt, height_pt, depth_pt = self.do_typeset(expr, self.texmessages_run_default + self.texmessages_run + texmessages)
  File "C:\Python34\lib\site-packages\pyx\text.py", line 1184, in do_typeset
    self.do_start()
  File "C:\Python34\lib\site-packages\pyx\text.py", line 1326, in do_start
    super().do_start()
  File "C:\Python34\lib\site-packages\pyx\text.py", line 1139, in do_start
    self.popen = config.Popen(cmd, stdin=config.PIPE, stdout=config.PIPE, stderr=config.STDOUT, bufsize=0)
  File "C:\Python34\lib\site-packages\pyx\config.py", line 190, in Popen
    return subprocess.Popen(cmd, *args, **kwargs)
  File "C:\Python34\lib\subprocess.py", line 858, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1111, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

Solution

  • PyX uses TeX for generating text output. The traceback you're showing comes from the inability to start the TeX interpreter. In line 1139 of text.py shown in the traceback, cmd will contain the string tex and the error comes from the fact, that the subprocess module fails to find this executable. In case you have a TeX installation already, you might either setup the PATH environment variable to include the search path of the TeX executables, or you can configure PyX using the pyxrc to use the full path name of the TeX executable. In case you have no TeX installation yet, just install a TeX distribution like TeX Live or MiKTeX. PyX should be able to run with both of them ... and other TeX distrubutions as well.