105

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?

4
  • 32
    relevant: github.com/matplotlib/matplotlib/pull/5640. The suggestion there is to delete the contents of ~/.cache/matplotlib and try again. It may be a permissions issue - It shouldn't be building that cache every time
    – tmdavison
    Jan 13, 2016 at 16:00
  • I hadn't read the latest comments. Thanks! Jan 14, 2016 at 13:37
  • 7
    This worked for me. On Ubuntu 14.04.2 with python 2.7 I deleted all of the files in ~/.cache/matplotlib/ . At first I thought it didn't work because I got the warning afterward. But after the cache files were rebuilt the warning went away. :) Jan 31, 2016 at 17:58
  • In a mod_wsgi+apache httpd+centos combination - when a request is sent from browser the httpd simply waits saying font cache is being built....It waits for more than 6 minutes and goes on and on....and never completes the font update. Could you please suggest how to solve this? Thanks
    – Vinodh
    Jul 9, 2016 at 1:23

8 Answers 8

117

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

6
  • 6
    I am on OSX El Capitan and this does not solve the issue. Any thoughts? Feb 6, 2016 at 21:49
  • 2
    On El Capitan I also had to remove ~/.cache/fontList or similar. Feb 22, 2016 at 20:37
  • 31
    mpl.get_cachedir() will show the cache location docs
    – Lenna
    Mar 21, 2016 at 15:06
  • 2
    I am on OS X El Capitan and this resolves the issue.
    – nos
    Jun 14, 2016 at 16:42
  • 6
    Note that after deleting these files you'll still get the warning one more time -- the next time you import matplotlib. After that you're set.
    – mattsilver
    Sep 8, 2016 at 16:02
25

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)
12

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/*
2
  • Worked for me on macOS X El Captain. I have the impression that it made faster loading other libraries as well.
    – SeF
    Oct 29, 2016 at 15:24
  • worked on macOS 10.12. On 2nd load, don't get the message anymore.
    – Demis
    Feb 28, 2018 at 19:28
9

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

5
  • Welcome to Stack Overflow! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Apr 16, 2016 at 17:03
  • I am running Jupyter notebook on Mac OSX El Capitan. I ran sudo jupyter notebook then import matplotlib.pyplot in a notebook and it solved my problem.
    – kungphil
    Jun 20, 2016 at 10:06
  • I've been struggling with this for months and this solved it! I'm on OS 10.9.5.
    – user2821
    Aug 1, 2016 at 14:36
  • 1
    Well, if you take a look at accepted answer, you'll see all you've done is that you have solved the problem by changing the user, and since there's no ~/.matplotlib in root home directory problem vanishes.
    – Rsh
    Sep 15, 2016 at 11:03
  • @Rsh No, the answers saying to use root permissions say that running it once as root makes it so it doesn't build the cache again if you run as a regular user after. Anyway, this didn't work for me.
    – sudo
    Jan 26, 2017 at 3:28
4

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!

0

HI 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
0

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.

-1

This worked for me:

sudo apt-get install libfreetype6-dev libxft-dev

Not the answer you're looking for? Browse other questions tagged or ask your own question.