1

我正在使用 pyx 做一些工作,这是用于可定制数据图形和可视化的 python 模块。问题是,即使直接复制粘贴最基本的图形代码示例,也会返回损坏的文件和错误。我对 python 比较陌生,我以前从未见过这样的错误,这让我头疼。我之前运行过简单的画布绘制,效果很好。这里发生了什么?

代码:

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") 

红色错误文本:

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
4

1 回答 1

1

PyX 使用 TeX 生成文本输出。您显示的回溯来自无法启动 TeX 解释器。在回溯中显示的 text.py 的第 1139 行中,cmd将包含字符串tex,错误来自于子进程模块无法找到此可执行文件的事实。如果您已经安装了 TeX,您可以设置 PATH 环境变量以包含 TeX 可执行文件的搜索路径,或者您可以使用 pyxrc 配置 PyX 以使用 TeX 可执行文件的完整路径名。如果您还没有安装 TeX,只需安装 TeX 发行版,例如TeX LiveMiKTeX。PyX 应该能够与它们一起运行......以及其他 TeX 分布。

于 2014-10-22T05:34:54.797 回答