Search code examples
pythonpathtracebackmiktexpyx

How to fix traceback error in Pyx module with Python?


I am trying to run in PyX module in Python.

It is a simple program called "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")

I want to do this to make plot.

I run it as normal

 C:\Users\Tony>py myplot.py

But I get strange and long error message:

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

How to fix this error and get my plot? How to fix this error and get my plot? How to fix this error and get my plot?How to fix this error and get my plot? How to fix this error and get my plot? How to fix this error and get my plot? How to fix this error and get my plot? How to fix this error and get my plot? How to fix this error and get my plot? How to fix this error and get my plot?How to fix this error and get my plot?How to fix this error and get my plot? How to fix this error and get my plot?How to fix this error and get my plot?

Any help is much appreciated. Thank you


Solution

  • You can fix it by adding the line

    text.set(engine=text.TexEngine, texmessages_end=[text.texmessage.ignore])
    

    immediately after the import statement. However, this will just silence the issue. A proper fix will be part of a future PyX release (see https://github.com/pyx-project/pyx/issues/8).