matplotlib taking time when being imported

Question:

I just upgraded to the latest stable release of matplotlib (1.5.1) and everytime I import matplotlib I get this message:

/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')

… which always stalls for a few seconds.

Is this the expected behaviour? Was it the same also before, but just without the printed message?

Asked By: Ricky Robinson

||

Answers:

As tom suggested in the comment above, deleting the files:

fontList.cache
fontList.py3k.cache 
tex.cache 

solve the problem.
In my case the files were under:

`~/.matplotlib`

EDITED

A couple of days ago the message appeared again, I deleted the files in the locations mention above without any success. I found that as suggested here by T Mudau there’s an extra location with text cache files is: ~/.cache/fontconfig

Answered By: Hugo

On OSX Yosemite (version 10.10.15), the following worked for me:

  • remove the cache files from this directory as well: ~/.cache/fontconfig (as per tom’s suggestion)
    rm -rvf ~/.cache/fontconfig/*
  • also removed .cache files in ~/.matplotlib (as per Hugo’s suggestion)
    rm -rvf ~/.matplotlib/*
Answered By: robbbyr

I ran the python code w. sudo and it cured it…my guess was that there wasn’t permission to write that table… good luck!

Answered By: C a t

I ran the python code using sudo just once, and it resolved the warning for me.
Now it runs faster. Running without sudo gives no warning at all.

Cheers

Answered By: Awais

This worked for me:

sudo apt-get install libfreetype6-dev libxft-dev
Answered By: mykahveli

Confirmed Hugo’s approach works for Ubuntu 14.04 LTS/matplotlib 1.5.1:

  • deleted ~/.cache/matplotlib/fontList.cache
  • ran code, again the warning was issued (assumption: is rebuilding the cache correctly)
  • ran code again, no more warning (finally)
Answered By: Bill Gale

HI you must find this file : font_manager.py in my case : C:UsersgustavoAnaconda3Libsite-packagesmatplotlib 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('', 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
Answered By: Gus Ch

This worked for me on Ubuntu 16.04 LST with Python 3.5.2 | Anaconda 4.2.0 (64-bit). I deleted all of the files in ~/.cache/matplotlib/.

sudo rm -r fontList.py3k.cache tex.cache 

At first I thought it wouldn’t work, because I got the warning afterward. But after the cache files were rebuilt the warning went away. So, close your file, and reopen again(open again), it has no warning.

Answered By: Theon.Soong
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.