PyX使用TeX生成文本输出。您显示的回溯来自于无法启动TeX解释器。在回溯中显示的text.py的第1139行中,
我正在使用pyx做一些工作,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:UsersUserDesktoptest.py", line 9, in <module>
g.writeEPSfile("x")
File "C:Python34libsite-packagespyxcanvas.py", line 50, in wrappedindocument
return method(d, file, **write_kwargs)
File "C:Python34libsite-packagespyxdocument.py", line 180, in writeEPSfile
pswriter.EPSwriter(self, f, **kwargs)
File "C:Python34libsite-packagespyxpswriter.py", line 142, in __init__
page.processPS(pagefile, self, acontext, registry, pagebbox)
File "C:Python34libsite-packagespyxdocument.py", line 130, in processPS
self._process("processPS", *args)
File "C:Python34libsite-packagespyxdocument.py", line 78, in _process
bbox.set(self.canvas.bbox()) # this bbox is not accurate
File "C:Python34libsite-packagespyxgraphgraph.py", line 181, in bbox
self.finish()
File "C:Python34libsite-packagespyxgraphgraph.py", line 303, in finish
self.doaxes()
File "C:Python34libsite-packagespyxgraphgraph.py", line 580, in doaxes
self.dolayout()
File "C:Python34libsite-packagespyxgraphgraph.py", line 564, in dolayout
self.doaxiscreate(axisname)
File "C:Python34libsite-packagespyxgraphgraph.py", line 240, in doaxiscreate
self.axes[axisname].create()
File "C:Python34libsite-packagespyxgraphaxisaxis.py", line 620, in create
self.linkedto.docreate()
File "C:Python34libsite-packagespyxgraphaxisaxis.py", line 525, in docreate
self._createfunction(*self._createargs, **self._createkwargs)
File "C:Python34libsite-packagespyxgraphgraph.py", line 240, in doaxiscreate
self.axes[axisname].create()
File "C:Python34libsite-packagespyxgraphaxisaxis.py", line 591, in create
self.canvas = self.axis.create(self.data, self.positioner, self.graphtexrunner, self.errorname)
File "C:Python34libsite-packagespyxgraphaxisaxis.py", line 250, in create
return _regularaxis._create(self, data, positioner, graphtexrunner, self.parter, self.rater, errorname)
File "C:Python34libsite-packagespyxgraphaxisaxis.py", line 220, in _create
variants[0].storedcanvas = layout(variants[0])
File "C:Python34libsite-packagespyxgraphaxisaxis.py", line 141, in layout
self.painter.paint(canvas, data, self, positioner)
File "C:Python34libsite-packagespyxgraphaxispainter.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:Python34libsite-packagespyxtext.py", line 1408, in wrapped
return f(self, *args, **kwargs)
File "C:Python34libsite-packagespyxtext.py", line 1439, in text_pt
return self.instance.text_pt(*args, **kwargs)
File "C:Python34libsite-packagespyxtext.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:Python34libsite-packagespyxtext.py", line 1184, in do_typeset
self.do_start()
File "C:Python34libsite-packagespyxtext.py", line 1326, in do_start
super().do_start()
File "C:Python34libsite-packagespyxtext.py", line 1139, in do_start
self.popen = config.Popen(cmd, stdin=config.PIPE, stdout=config.PIPE, stderr=config.STDOUT, bufsize=0)
File "C:Python34libsite-packagespyxconfig.py", line 190, in Popen
return subprocess.Popen(cmd, *args, **kwargs)
File "C:Python34libsubprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:Python34libsubprocess.py", line 1111, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
cmd
将包含字符串tex
,错误来自子流程模块未能找到此可执行文件。如果您已经安装了TeX,您可以设置PATH环境变量以包括TeX可执行文件的搜索路径,也可以使用pyxrc配置PyX以使用TeX可运行文件的完整路径名。如果您还没有安装TeX,只需安装TeX发行版,如TeX Live或MiKTeX。PyX应该能够同时运行它们。。。以及其他TeX发行版。