gpt4 book ai didi

尽管代码很好,但使用 Pyx 模块时出现 Python 错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:07:59 25 4
gpt4 key购买 nike

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

代码:

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

最佳答案

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

关于尽管代码很好,但使用 Pyx 模块时出现 Python 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26496093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com