107

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?

Ricky Robinson
  • 21,798
  • 42
  • 129
  • 185
  • 32
    relevant: https://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 '16 at 16:00
  • I hadn't read the latest comments. Thanks! – Ricky Robinson Jan 14 '16 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. :) – Nancy Poekert Jan 31 '16 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 09 '16 at 01:23

8 Answers8

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

Community
  • 1
  • 1
Hugo
  • 1,366
  • 1
  • 9
  • 8
  • 6
    I am on OSX El Capitan and this does not solve the issue. Any thoughts? – mar tin Feb 06 '16 at 21:49
  • 2
    On El Capitan I also had to remove ~/.cache/fontList or similar. – peanut_butter Feb 22 '16 at 20:37
  • 31
    `mpl.get_cachedir()` will show the cache location [docs](http://matplotlib.org/faq/troubleshooting_faq.html#matplotlib-configuration-and-cache-directory-locations) – Lenna Mar 21 '16 at 15:06
  • I am also on OS X El Capitan. I noticed the first time I imported matplotlib.pyplot after removing the cache files, I still got the same error but the second time it ran much quicker. – Steven C. Howell Jun 01 '16 at 13:26
  • 2
    I am on OS X El Capitan and this resolves the issue. – nos Jun 14 '16 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 08 '16 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)
Bill Gale
  • 1,238
  • 1
  • 14
  • 14
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/*
SherylHohman
  • 16,580
  • 17
  • 88
  • 94
robbbyr
  • 131
  • 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 '16 at 15:24
  • worked on macOS 10.12. On 2nd load, don't get the message anymore. – Demis Feb 28 '18 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

Awais
  • 91
  • 1
  • 3
  • Welcome to Stack Overflow! Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Enamul Hassan Apr 16 '16 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 '16 at 10:06
  • I've been struggling with this for months and this solved it! I'm on OS 10.9.5. – user2821 Aug 01 '16 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 '16 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 '17 at 03: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!

catubc
  • 488
  • 3
  • 16
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
Gus Ch
  • 9
  • 2
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.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Theon Soong
  • 109
  • 1
  • 5
-1

This worked for me:

sudo apt-get install libfreetype6-dev libxft-dev
mykahveli
  • 113
  • 4