如何使用 Python 修复 Pyx 模块中的回溯错误?
Posted
技术标签:
【中文标题】如何使用 Python 修复 Pyx 模块中的回溯错误?【英文标题】:How to fix traceback error in Pyx module with Python? 【发布时间】:2019-08-09 08:06:34 【问题描述】:我正在尝试在 Python 的 PyX 模块中运行。
这是一个名为“mplot.py”的简单程序:
from pyx import *
g = graph.graphxy(width=8)
g.plot(graph.data.function("y(x)=sin(x)/x", min=-15, max=15))
g.writePDFfile("function")
我想这样做是为了制作情节。
我正常运行
C:\Users\Tony>py myplot.py
但我收到奇怪而冗长的错误消息:
Traceback (most recent call last):
File "myplot.py", line 4, in <module>
g.writePDFfile("function")
File "C:\Users\Tony\Programs\Python\Python37-32\lib\sitepackages\pyx\canvas.py", line 50, in wrappedindocument
return method(d, file, **write_kwargs)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\document.py", line 193, in writePDFfile
pdfwriter.PDFwriter(self, f, **kwargs)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\pdfwriter.py", line 316, in __init__
catalog = PDFcatalog(document, self, registry)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\pdfwriter.py", line 143, in __init__
self.PDFpages = PDFpages(document, writer, registry)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\pdfwriter.py", line 202, in __init__
page = PDFpage(page, pageno, self, writer, registry)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\pdfwriter.py", line 236, in __init__
self.PDFcontent = PDFcontent(page, writer, self.pageregistry)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\pdfwriter.py", line 268, in __init__
page.processPDF(contentfile, awriter, acontext, registry, self.bbox)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\document.py", line 135, in processPDF
self._process("processPDF", *args)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\document.py", line 129, in _process
getattr(cc, processMethod)(contentfile, writer, context, registry, bbox)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\graph\graph.py", line 191, in processPDF
canvas.canvas.processPDF(self, file, writer, context, registry, bbox)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\canvas.py", line 238, in processPDF
item.processPDF(file, writer, context, registry, nbbox)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\canvas.py", line 238, in processPDF
item.processPDF(file, writer, context, registry, nbbox)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\canvas.py", line 238, in processPDF
item.processPDF(file, writer, context, registry, nbbox)
[Previous line repeated 1 more time]
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\text.py", line 887, in processPDF
self.dvicanvas.processPDF(file, writer, context, registry, abbox)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\text.py", line 851, in dvicanvas
self.do_finish()
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\text.py", line 1212, in do_finish
self.go_finish()
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\text.py", line 1338, in go_finish
self._execute("\\end%\n", self.texmessages_end_default +
self.texmessages_end, STATE_TYPESET, STATE_DONE)
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\text.py", line 1125, in _execute
raise e
File "C:\Users\Tony\Programs\Python\Python37-32\lib\site
packages\pyx\text.py", line 1103, in _execute
raise TexResultError("TeX dvifile messages expected")
pyx.text.TexResultError: TeX dvifile messages expected
The expression passed to TeX was:
\end%
After parsing the return message from TeX, the following was left:
*(see the transcript file for additional information)
Output written on "C:\Users\Tony\Temp\pyx3z6ter8i\texp
ut.dvi" (25 pages, 1800 bytes).
Transcript written on "C:\Users\Tony\Temp\pyx3z6ter8i\
texput.log".
如何解决这个错误并得到我的情节? 如何修复此错误并获取我的情节? 如何修复此错误并获取我的情节?如何修复此错误并获取我的情节? 如何修复此错误并获取我的情节? 如何修复此错误并获取我的情节? 如何修复此错误并获取我的情节? 如何修复此错误并获取我的情节? 如何修复此错误并获取我的情节? 如何修复此错误并获取我的绘图?如何修复此错误并获取我的绘图?如何修复此错误并获取我的绘图? 如何修复此错误并获取我的绘图?如何修复此错误并获取我的绘图?
非常感谢任何帮助。谢谢
【问题讨论】:
我运行了你的代码,它在我的系统上运行。你是如何安装pyx
的?
使用 pip 安装 pyx。不知道报错是和PATH还是路径有关?
【参考方案1】:
你可以通过添加行来修复它
text.set(engine=text.TexEngine, texmessages_end=[text.texmessage.ignore])
紧跟在 import 语句之后。但是,这只会使问题沉默。适当的修复将成为未来 PyX 版本的一部分(请参阅https://github.com/pyx-project/pyx/issues/8)。
【讨论】:
另外,您可以测试github.com/pyx-project/pyx/commit/…是否为您解决了问题。它应该,但我无法测试自己...... 对不起,我如何测试这个 github 链接是否是修复?我将代码复制粘贴到某处? 好的,你可以下载补丁github.com/pyx-project/pyx/commit/…或者完整文件raw.githubusercontent.com/pyx-project/pyx/… 对不起,我下载了补丁放在哪里?执行什么命令? 要应用补丁,您需要使用补丁实用程序,这对于软件开发人员来说非常常见。现在,对您来说更早的是指向完整文件 text.py 的第二个链接(因为您自己不知道如何使用补丁文件)。它已经应用了补丁。您需要用此文件替换系统上的 text.py 文件,并检查问题是否已在没有我在回答中建议的附加行的情况下得到解决。以上是关于如何使用 Python 修复 Pyx 模块中的回溯错误?的主要内容,如果未能解决你的问题,请参考以下文章