Incompatible libpng versions when running matplotlib

I'm trying to use facebook research's Detectron. When I run it, it gives me the following error:

libpng warning: Application built with libpng-1.6.21 but running with 1.5.12
Traceback (most recent call last):
  File "tools/infer_simple.py", line 147, in <module>
    main(args)
  File "tools/infer_simple.py", line 139, in main
    kp_thresh=2
  File "/home/sid/DETECTRON/detectron/lib/utils/vis.py", line 391, in vis_one_image
    fig.savefig(os.path.join(output_dir, '{}'.format(output_name)), dpi=dpi)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1834, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2267, in print_figure
    **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 2595, in print_pdf
    file.finalize()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 595, in finalize
    self.writeImages()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 1430, in writeImages
    ob.id, smaskObject)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 1416, in _writeImg
    self._writePng(data)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 1366, in _writePng
    _png.write_png(data, buffer)
RuntimeError: Could not create write struct

I'm running Ubuntu 16.04. I don't know where the application is finding the libpng 1.5.12 version. I could not find it in my system. I installed libpng16-16. It still gives me the same error. I tried out other solutions suggested on the platform but they didn't work

Upvotes: 0

Views: 259

Answers (1)

code_onkel
code_onkel

Reputation: 2972

I guess the problem is that you sudo pip installed matplotlib and that the libpng version that is shipped with the manylinux installation package of matplotlib is confused with the libpng version that was installed by apt. I recommend using matplotlib inside a virtual environment.

# create venv
virtualenv ~/matplotlib-venv

# activate venv
source ~/matplotlib-venv/bin/activate

# install matplotlib
pip install matplotlib
pip install <everything else you need>

# run your script
python ~/path/to/your/srcript.py

Upvotes: 1

Related Questions