1

I was trying to plot a graphic with matplotlib in Jupyter and then with only the 'pylab inline' the following error shows up. I'm working with python 3.x and anaconda in a macbook. I found similar trends (for example this) with some potential solutions but they didn't work. I have tried everything but nothing works. I would really appreciate any help.

My code:

%pylab inline

which produces the following error:

    ---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
//anaconda/lib/python3.6/site-packages/matplotlib/font_manager.py in <module>()
   1429         try:
-> 1430             fontManager = pickle_load(_fmcache)
   1431             if (not hasattr(fontManager, '_version') or

//anaconda/lib/python3.6/site-packages/matplotlib/font_manager.py in pickle_load(filename)
    965     """
--> 966     with open(filename, 'rb') as fh:
    967         data = pickle.load(fh)

FileNotFoundError: [Errno 2] No such file or directory: '/Users/sebasg167/.matplotlib/fontList.py3k.cache'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-2-d4543581fa9d> in <module>()
----> 1 get_ipython().magic('pylab inline')

//anaconda/lib/python3.6/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

//anaconda/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 

<decorator-gen-105> in pylab(self, line)

//anaconda/lib/python3.6/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

//anaconda/lib/python3.6/site-packages/IPython/core/magics/pylab.py in pylab(self, line)
    154             import_all = not args.no_import_all
    155 
--> 156         gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)
    157         self._show_matplotlib_backend(args.gui, backend)
    158         print ("Populating the interactive namespace from numpy and matplotlib")

//anaconda/lib/python3.6/site-packages/IPython/core/interactiveshell.py in enable_pylab(self, gui, import_all, welcome_message)
   2984         from IPython.core.pylabtools import import_pylab
   2985 
-> 2986         gui, backend = self.enable_matplotlib(gui)
   2987 
   2988         # We want to prevent the loading of pylab to pollute the user's

//anaconda/lib/python3.6/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   2945                 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
   2946 
-> 2947         pt.activate_matplotlib(backend)
   2948         pt.configure_inline_support(self, backend)
   2949 

//anaconda/lib/python3.6/site-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
    292     matplotlib.rcParams['backend'] = backend
    293 
--> 294     import matplotlib.pyplot
    295     matplotlib.pyplot.switch_backend(backend)
    296 

//anaconda/lib/python3.6/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

//anaconda/lib/python3.6/site-packages/matplotlib/colorbar.py in <module>()
     34 import matplotlib.collections as collections
     35 import matplotlib.colors as colors
---> 36 import matplotlib.contour as contour
     37 import matplotlib.cm as cm
     38 import matplotlib.gridspec as gridspec

//anaconda/lib/python3.6/site-packages/matplotlib/contour.py in <module>()
     20 import matplotlib.colors as colors
     21 import matplotlib.collections as mcoll
---> 22 import matplotlib.font_manager as font_manager
     23 import matplotlib.text as text
     24 import matplotlib.cbook as cbook

//anaconda/lib/python3.6/site-packages/matplotlib/font_manager.py in <module>()
   1438             raise
   1439         except:
-> 1440             _rebuild()
   1441     else:
   1442         _rebuild()

//anaconda/lib/python3.6/site-packages/matplotlib/font_manager.py in _rebuild()
   1417         global fontManager
   1418 
-> 1419         fontManager = FontManager()
   1420 
   1421         if _fmcache:

//anaconda/lib/python3.6/site-packages/matplotlib/font_manager.py in __init__(self, size, weight)
   1071         self.afmfiles = findSystemFonts(paths, fontext='afm') + \
   1072             findSystemFonts(fontext='afm')
-> 1073         self.afmlist = createFontList(self.afmfiles, fontext='afm')
   1074         if len(self.afmfiles):
   1075             self.defaultFont['afm'] = self.afmfiles[0]

//anaconda/lib/python3.6/site-packages/matplotlib/font_manager.py in createFontList(fontfiles, fontext)
    589                 continue
    590             try:
--> 591                 prop = afmFontProperty(fpath, font)
    592             except KeyError:
    593                 continue

//anaconda/lib/python3.6/site-packages/matplotlib/font_manager.py in afmFontProperty(fontpath, font)
    498     """
    499 
--> 500     name = font.get_familyname()
    501     fontname = font.get_fontname().lower()
    502 

//anaconda/lib/python3.6/site-packages/matplotlib/afm.py in get_familyname(self)
    523         extras = (br'(?i)([ -](regular|plain|italic|oblique|bold|semibold|'
    524                   br'light|ultralight|extra|condensed))+$')
--> 525         return re.sub(extras, '', name)
    526 
    527     @property

//anaconda/lib/python3.6/re.py in sub(pattern, repl, string, count, flags)
    189     a callable, it's passed the match object and must return
    190     a replacement string to be used."""
--> 191     return _compile(pattern, flags).sub(repl, string, count)
    192 
    193 def subn(pattern, repl, string, count=0, flags=0):

TypeError: cannot use a bytes pattern on a string-like object
Community
  • 1
  • 1
  • A traceback alone without a [mcve] of the problem is completely useless. Please [edit] your question with a minimal example that reproduced the problem. – ImportanceOfBeingErnest Feb 24 '17 at 08:44
  • Hi ImportanceOfBeingErnest , the problem is that in this case the problem came from the very basic ' %pylab inline'. As you can see in similar trends the problem is coming from a font_manager.py file. Nothing related with my code, for that reason I didn´t posted it. – Sebastian Garzon Feb 25 '17 at 02:09

1 Answers1

0

You must find this file : font_manager.py in my case : C:\Users\gustavo\Anaconda3\Lib\site-packages\matplotlib\ font_manager.py

and FIND def win32InstalledFonts(directory=None, fontext='ttf') and replace by :

def win32InstalledFonts(directory=None, fontext='ttf'): """ Search for fonts in the specified font directory, or use the system directories if none given. A list of TrueType font filenames are returned by default, or AFM fonts if fontext == 'afm'. """

from six.moves import winreg
if directory is None:
    directory = win32FontDirectory()

fontext = get_fontext_synonyms(fontext)

key, items = None, {}
for fontdir in MSFontDirectories:
    try:
        local = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir)
    except OSError:
        continue

    if not local:
        return list_fonts(directory, fontext)
    try:
        for j in range(winreg.QueryInfoKey(local)[1]):
            try:
                key, direc, any = winreg.EnumValue(local, j)
                if not is_string_like(direc):
                    continue
                if not os.path.dirname(direc):
                    direc = os.path.join(directory, direc)
                    direc = direc.split('\0', 1)[0]

                if os.path.splitext(direc)[1][1:] in fontext:
                    items[direc] = 1
            except EnvironmentError:
                continue
            except WindowsError:
                continue
            except MemoryError:
                continue
        return list(six.iterkeys(items))
    finally:
        winreg.CloseKey(local)
return None
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Gus Ch
  • 9
  • 2