Skip to content

ERROR: matplotlib.tests.test_backend_pgf.test_pdflatex on Python 3.x #1118

Closed

Description

@mdboom

I'm getting this on Python 3.x only.

======================================================================
ERROR: matplotlib.tests.test_backend_pgf.test_pdflatex
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mdboom/python3/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/testing/decorators.py", line 39, in failer
    result = f(*args, **kwargs)
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/tests/test_backend_pgf.py", line 30, in backend_switcher
    result = func(*args, **kwargs)
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/tests/test_backend_pgf.py", line 82, in test_pdflatex
    compare_figure('pgf_pdflatex.pdf')
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/tests/test_backend_pgf.py", line 40, in compare_figure
    plt.savefig(actual)
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/pyplot.py", line 475, in savefig
    return fig.savefig(*args, **kwargs)
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/figure.py", line 1229, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/backend_bases.py", line 2089, in print_figure
    **kwargs)
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/backends/backend_pgf.py", line 694, in print_pdf
    self.print_pgf("figure.pgf")
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/backends/backend_pgf.py", line 674, in print_pgf
    renderer = RendererPgf(self.figure, fh)
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/backends/backend_pgf.py", line 358, in __init__
    self.latexManager = LatexManagerFactory.get_latex_manager()
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/backends/backend_pgf.py", line 205, in get_latex_manager
    new_inst = LatexManager()
  File "/home/mdboom/python3/lib/python3.2/site-packages/matplotlib/backends/backend_pgf.py", line 243, in __init__
    stdout, stderr = latex.communicate(self.latex_header + latex_end)
  File "/usr/lib64/python3.2/subprocess.py", line 819, in communicate
    return self._communicate(input)
  File "/usr/lib64/python3.2/subprocess.py", line 1425, in _communicate
    stdout, stderr = self._communicate_with_poll(input)
  File "/usr/lib64/python3.2/subprocess.py", line 1492, in _communicate_with_poll
    input_offset += os.write(fd, chunk)
TypeError: 'str' does not support the buffer interface

Activity

  1. ghost assigned on Aug 20, 2012
  2. pwuertz commented on Aug 21, 2012

    @pwuertz
    Contributor

    I have never worked with python3 before :/, but it looks like the py3 distinction between strings and bytes. Subprocess.communicate requires a byte buffer that must be explicitly encoded from a str.. (self.latex_header + latex_end).encode('utf-8')..

    I'll try to setup a python 3 environment then ^^

  3. pwuertz commented on Aug 21, 2012

    @pwuertz
    Contributor

    Ok. Another problem. For me, in python3 this doesn't work anymore:

    import codecs
    import subprocess
    
    proc = subprocess.Popen(["echo"], stdin=subprocess.PIPE,
                                      stdout=subprocess.PIPE,
                                      universal_newlines=True)
    proc_stdin = codecs.getwriter("utf8")(proc.stdin)
    proc_stdin.write("")
    proc.communicate()

    Apparently, the universal_newlines support is gone. It works if you omit this option. I don't know if this is a problem for windows or osx. For windows it's probably ok since I check for a latex prompt after newline.. and even with '\r\n' the newline is still the last character of a line. What about osx? Are they still using '\r' as a newline? I better find someone to test this :)

  4. pwuertz commented on Aug 21, 2012

    @pwuertz
    Contributor

    All right, I rewrote the part for the communication with the latex subprocess. Python3 seems to have trouble with subprocess+codecs+latex, so I'm using bytebuffers for reading the stdout now. Python2 tests pass, running a python3 example works, but I can't run the test suite with py3 yet (#745).

  5. added a commit that references this issue on Aug 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions