Ipython/ pylab/ matplotlib installation and initia

2019-05-01 09:39发布

问题:

I installed matplotlib, anaconda, ipython on OS X El Captain. However even after trying to set up the environment variables in all possible ways, I am unable to start up the ipython shell --pylab version.

Here is the error.

ImportError: dlopen(/Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: @rpath/libpng16.16.dylib
Referenced from: /Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
Reason: Incompatible library version: _png.so requires version 40.0.0 or later, but libpng16.16.dylib provides version 39.0.0

Initially, matplotlib wasn't showing up after a normal pip install matplotlib. After reinstalling matplotlib from 'conda' using conda install -c conda-forge matplotlib=1.5.2, I am not getting a import error pf package not found but the pylab version is still not functional. I tried upgrading libpng library, and installed it in /usr/local but then also no use. I don't know how _png.so is to be upgraded in the /anaconda/site-packages/matplotlib folder. I have also tried setting up the environment variables of the libpng.x.dylib library I don't know why its not working or may be I have not done it correctly.

Here is the full screenshot just in case its necessary:-

IPython 5.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
TerminalIPythonApp WARNING | Eventloop or matplotlib integration failed. Is matplotlib installed?

ImportError                               Traceback (most recent call last)
/Users/apple/anaconda/lib/python2.7/site-packages/IPython/core/shellapp.pyc in <lambda>(key)
    196         shell = self.shell
    197         if self.pylab:
--> 198             enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all)
    199             key = self.pylab
    200         elif self.matplotlib:

/Users/apple/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_pylab(self, gui, import_all, welcome_message)
     2972         from IPython.core.pylabtools import import_pylab
     2973 
---> 2974         gui, backend = self.enable_matplotlib(gui)
     2975 
     2976         # We want to prevent the loading of pylab to pollute the user's

/Users/apple/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_matplotlib(self, gui)
     2933 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
     2934 
 --->2935         pt.activate_matplotlib(backend)
     2936         pt.configure_inline_support(self, backend)
     2937 

/Users/apple/anaconda/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in activate_matplotlib(backend)
     293     matplotlib.rcParams['backend'] = backend
     294 
 --> 295     import matplotlib.pyplot
     296     matplotlib.pyplot.switch_backend(backend)
     297 

/Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
     27 from cycler import cycler
     28 import matplotlib
 --->29 import matplotlib.colorbar
     30 from matplotlib import style
     31 from matplotlib import _pylab_helpers, interactive

/Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>()
     32 import matplotlib.artist as martist
     33 import matplotlib.cbook as cbook
---> 34 import matplotlib.collections as collections
     35 import matplotlib.colors as colors
     36 import matplotlib.contour as contour

/Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/collections.py in <module>()
     25 import matplotlib.artist as artist
     26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
     28 import matplotlib.path as mpath
 29 from matplotlib import _path

/Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py in <module>()
     60 
     61 import matplotlib.tight_bbox as tight_bbox
---> 62 import matplotlib.textpath as textpath
     63 from matplotlib.path import Path
     64 from matplotlib.cbook import mplDeprecation, warn_deprecated

/Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py in <module>()
     16 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
     17 from matplotlib.ft2font import LOAD_TARGET_LIGHT
---> 18 from matplotlib.mathtext import MathTextParser
     19 import matplotlib.dviread as dviread
     20 from matplotlib.font_manager import FontProperties

/Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/mathtext.py in <module>()
     58 
     59 import matplotlib.colors as mcolors
---> 60 import matplotlib._png as _png
     61 ####################
     62 

ImportError: dlopen(/Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: @rpath/libpng16.16.dylib
  Referenced from: /Users/apple/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
  Reason: Incompatible library version: _png.so requires version 40.0.0 or later, but libpng16.16.dylib provides version 39.0.0

回答1:

Try:

brew uninstall libpng
conda uninstall matplotlib
conda install matplotlib