matplotlib在导入时需要时间

Ric*_*son 103 python matplotlib

我刚刚升级到matplotlib(1.5.1)的最新稳定版本,每次我导入matplotlib我收到此消息:

/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.')
Run Code Online (Sandbox Code Playgroud)

...总是停顿几秒钟.

这是预期的行为吗?以前是否也一样,但是没有印刷的信息?

小智 115

正如汤姆在上面的评论中所建议的,删除文件:

fontList.cache
fontList.py3k.cache 
tex.cache 
Run Code Online (Sandbox Code Playgroud)

解决这个问题.在我的情况下,文件在:

`~/.matplotlib`
Run Code Online (Sandbox Code Playgroud)

EDITED

几天前,该消息再次出现,我删除了上述位置的文件,没有任何成功.我发现,建议在这里通过牛逼穆道有一个额外的位置信息与文本缓存文件是:~/.cache/fontconfig

  • `mpl.get_cachedir()`将显示缓存位置[docs](http://matplotlib.org/faq/troubleshooting_faq.html#matplotlib-configuration-and-cache-directory-locations) (29认同)
  • 我在OSX El Capitan上,但这并没有解决问题.有什么想法吗? (6认同)
  • 请注意,删除这些文件后,您仍会再次收到警告 - 下次导入matplotlib时.之后你就定了. (6认同)
  • 在El Capitan我还必须删除〜/ .cache/fontList或类似的东西. (2认同)
  • 我在OS X El Capitan上,这解决了这个问题. (2认同)

Bil*_*ale 25

确认Hugo的方法适用于Ubuntu 14.04 LTS/matplotlib 1.5.1:

  • 删除〜/ .cache/matplotlib/fontList.cache
  • 运行代码,再次发出警告(假设:正在重建缓存)
  • 再次运行代码,没有更多的警告(最后)


小智 12

在OSX Yosemite(版本10.10.15)上,以下内容适用于我:

  • 从这个目录中删除缓存文件:〜/ .cache/fontconfig(根据tom的建议)
    rm -rvf ~/.cache/fontconfig/*
  • 还删除了〜/ .matplotlib中的.cache文件(根据Hugo的建议)
    rm -rvf ~/.matplotlib/*


小智 9

我只使用sudo运行一次python代码,它解决了我的警告.现在它运行得更快.没有sudo运行根本不会发出警告.

干杯