Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libpng error: Read Error when using matplotlib after setting usetex=True #16163

Closed
joaocaldeira opened this issue Jan 8, 2020 · 6 comments
Closed

Comments

@joaocaldeira
Copy link

joaocaldeira commented Jan 8, 2020

Bug report

Bug summary

On two different machines running Windows 10, I am getting the error libpng error: Read Error leading to python crashing when trying to plot after setting the option usetex=True in matplotlib. This has worked without problems before on these machines, I am not sure what changed since.

Code for reproduction and outcome

A minimum example, directly after creating a fresh environment with conda create --name libpngtest python=3 matplotlib libpng:

>>> import matplotlib.pyplot as plt
>>> from matplotlib import rc
>>> rc('text', usetex=True)
>>> plt.plot(1,2)
[<matplotlib.lines.Line2D object at 0x00000193015A8908>]
>>> plt.show()

At this point sometimes the python console just crashes out without any message, but I have also seen libpng error: Read Error printed before it crashes. Inside a jupyter notebook/lab, the kernel will restart and libpng error: Read Error appears in the terminal where jupyter is running between jupyter messages.

Matplotlib version

I have tried installing different libpng versions (1.6.32, 1.6.34, 1.6.36, 1.6.37) but all of them lead to the same outcome.

  • Operating system: Windows 10
  • Matplotlib version: 3.1.1 (but have tried with different versions, as changing the version of libpng results in different matplotlib versions)
  • Matplotlib backend: Qt5Agg
  • Python version: 3.7.6, but see comment under matplotlib version
  • Other libraries: libpng
  • Other software: MiKTeX 2.9

debugger output

The output after setting plt.set_loglevel("debug") is:

DEBUG:matplotlib.texmanager:serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: serif, font: Computer Modern Roman, info: ('cmr', '')
DEBUG:matplotlib.texmanager:sans-serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:sans-serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: sans-serif, font: Computer Modern Sans Serif, info: ('cmss', '')
DEBUG:matplotlib.texmanager:cursive font is not compatible with usetex.
DEBUG:matplotlib.texmanager:cursive font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: cursive, font: Zapf Chancery, info: ('pzc', '\\usepackage{chancery}')
DEBUG:matplotlib.texmanager:monospace font is not compatible with usetex.
DEBUG:matplotlib.texmanager:monospace font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: monospace, font: Computer Modern Typewriter, info: ('cmtt', '')
DEBUG:matplotlib.texmanager:following keys changed: ['text.latex.preamble', 'text.latex.unicode', 'text.latex.preview', 'font.family', 'font.serif', 'font.sans-serif', 'font.cursive', 'font.monospace']
DEBUG:matplotlib.texmanager:text.latex.preamble : None       ->
DEBUG:matplotlib.texmanager:text.latex.unicode  : None       -> True
DEBUG:matplotlib.texmanager:text.latex.preview  : None       -> False
DEBUG:matplotlib.texmanager:font.family         : None       -> ['sans-serif']
DEBUG:matplotlib.texmanager:font.serif          : None       -> ['DejaVu Serif', 'Bitstream Vera Serif', 'Computer Modern Roman', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif']
DEBUG:matplotlib.texmanager:font.sans-serif     : None       -> ['DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif']
DEBUG:matplotlib.texmanager:font.cursive        : None       -> ['Apple Chancery', 'Textile', 'Zapf Chancery', 'Sand', 'Script MT', 'Felipa', 'cursive']
DEBUG:matplotlib.texmanager:font.monospace      : None       -> ['DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Computer Modern Typewriter', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace']
DEBUG:matplotlib.texmanager:RE-INIT
old fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.texmanager:serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: serif, font: Computer Modern Roman, info: ('cmr', '')
DEBUG:matplotlib.texmanager:sans-serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:sans-serif font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: sans-serif, font: Computer Modern Sans Serif, info: ('cmss', '')
DEBUG:matplotlib.texmanager:cursive font is not compatible with usetex.
DEBUG:matplotlib.texmanager:cursive font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: cursive, font: Zapf Chancery, info: ('pzc', '\\usepackage{chancery}')
DEBUG:matplotlib.texmanager:monospace font is not compatible with usetex.
DEBUG:matplotlib.texmanager:monospace font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: monospace, font: Computer Modern Typewriter, info: ('cmtt', '')
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\1acea6f6c115d0ec7a634ed0529287b9.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.dviread:['kpsewhich', 'cmss10.tfm']
DEBUG:matplotlib.dviread:stdout:
b'C:/Program Files/MiKTeX 2.9/fonts/tfm/public/cm/cmss10.tfm\r\n'
DEBUG:matplotlib.dviread:stderr:
b''
DEBUG:matplotlib.dviread:opening tfm file C:/Program Files/MiKTeX 2.9/fonts/tfm/public/cm/cmss10.tfm
DEBUG:matplotlib.dviread:lh=18, bc=0, ec=127, nw=52, nh=16, nd=11
DEBUG:matplotlib.dviread:['kpsewhich', 'cmss10.vf']
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\d598be7bdc6e0eeebdc83c75321a7705.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.dviread:['kpsewhich', 'cmr10.tfm']
DEBUG:matplotlib.dviread:stdout:
b'C:/Program Files/MiKTeX 2.9/fonts/tfm/public/cm/cmr10.tfm\r\n'
DEBUG:matplotlib.dviread:stderr:
b''
DEBUG:matplotlib.dviread:opening tfm file C:/Program Files/MiKTeX 2.9/fonts/tfm/public/cm/cmr10.tfm
DEBUG:matplotlib.dviread:lh=18, bc=0, ec=127, nw=36, nh=16, nd=10
DEBUG:matplotlib.dviread:['kpsewhich', 'cmr10.vf']
DEBUG:matplotlib.dviread:['kpsewhich', 'cmmi10.tfm']
DEBUG:matplotlib.dviread:stdout:
b'C:/Program Files/MiKTeX 2.9/fonts/tfm/public/cm/cmmi10.tfm\r\n'
DEBUG:matplotlib.dviread:stderr:
b''
DEBUG:matplotlib.dviread:opening tfm file C:/Program Files/MiKTeX 2.9/fonts/tfm/public/cm/cmmi10.tfm
DEBUG:matplotlib.dviread:lh=18, bc=0, ec=127, nw=98, nh=15, nd=9
DEBUG:matplotlib.dviread:['kpsewhich', 'cmmi10.vf']
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\1acea6f6c115d0ec7a634ed0529287b9.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\14cf46b44d83e91d3e4f12cc60007df3.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\1acea6f6c115d0ec7a634ed0529287b9.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\217de38979bbb592496a29d181b7bbc4.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\1acea6f6c115d0ec7a634ed0529287b9.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\3233f296f4d6994ca99a0d418d6458d8.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\1acea6f6c115d0ec7a634ed0529287b9.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.dviread:Dvi: C:\Users\...\.matplotlib\tex.cache\e2c00e1750b187927439ebc0ca3a1a38.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
DEBUG:matplotlib.texmanager:fontconfig: sans-serifcmrcmsspzccmttd41d8cd98f00b204e9800998ecf8427e
@anntzer
Copy link
Contributor

anntzer commented Jan 8, 2020

Matplotlib master (and the future 3.2) no longer uses libpng (but Pillow instead) so this is only a 3.1.x thing; may be worth seeing what happens with e.g. the latest 3.2.0 rc release.

@joaocaldeira
Copy link
Author

Well, installing matplotlib 3.2.0-rc1 definitely changed things. Now the commands above triggered the installation of two TeX packages, cm-super and oberdiek, though the file it is looking for in oberdiek, ifvtex.sty, is no longer in oberdiek, so I'm stuck again. That's clearly a TeX issue though. Will circle back once I figure that one out.

@joaocaldeira
Copy link
Author

Ok, MiKTeX's (user-specific) package database needed updating, and after installing the cm-super and ifvtex packages, plotting works.

I'm not sure whether to close this issue. Plotting still only works on 3.2.0.

@anntzer anntzer added this to the v3.1.3 milestone Jan 10, 2020
@anntzer
Copy link
Contributor

anntzer commented Jan 12, 2020

So to confirm, the thing still fails on 3.1.x even after fixing your miktex install?

@joaocaldeira
Copy link
Author

Yes, the behavior on 3.1.1 has not changed.

@tacaswell
Copy link
Member

Given that this is fixed in 3.2 and the release of 3.2 in imminent, I'm going to close this as fixed (for 3.2). Thank you for reporting this @joaocaldeira and sorry for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants