Matplotlib AFM进口速度极慢 [英] Extremely slow import of matplotlib afm

查看:33
本文介绍了Matplotlib AFM进口速度极慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导入时间长得令人无法接受:

  from matplotlib import pylab as plt --> 3.0124739 secs

这是cProfile的输出,它清楚地显示问题出在afm.py,这是Adobe Font Metrics.的一些接口。Matplotlib版本为1.4.0-Ubuntu 14.04

         5994612 function calls (5992123 primitive calls) in 4.702 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      182    1.589    0.009    2.372    0.013 afm.py:220(_parse_kern_pairs)
      215    0.746    0.003    1.420    0.007 afm.py:180(_parse_char_metrics)
  1297990    0.410    0.000    0.410    0.000 {method 'split' of 'str' objects}
   839978    0.288    0.000    0.288    0.000 {method 'readline' of 'file' objects}
        2    0.254    0.127    4.185    2.093 font_manager.py:544(createFontList)
   843308    0.170    0.000    0.170    0.000 {method 'startswith' of 'str' objects}
   114276    0.168    0.000    0.205    0.000 afm.py:72(_to_list_of_floats)
1563800      0.125    0.000    0.125    0.000 {len}
   839220    0.117    0.000    0.117    0.000 {method 'rstrip' of 'str' objects}
   115290    0.116    0.000    0.119    0.000 {method 'decode' of 'str' objects}
   117775    0.086    0.000    0.086    0.000 afm.py:56(_to_int)
       20    0.061    0.003    0.061    0.003 {built-in method poll}
      520    0.040    0.000    0.040    0.000 {method 'get_sfnt' of 'FT2Font' objects}
     6910    0.036    0.000    0.036    0.000 {posix.stat}
     3372    0.025    0.000    0.038    0.000 posixpath.py:336(normpath)

您知道如何修复/禁用它吗?

编辑

回滚到1.3.1挽救了我的一天。现在运行时间为0.2秒。

推荐答案

我遇到了同样的问题。我发现,当您将matplotlib升级到较新的版本时,会发生这种情况。字体缓存文件与新版本不兼容,但显然没有重新创建。相反,每次在飞翔上都会创建字体列表。解决方案是删除matplotlib缓存目录(在我的示例中~/.cache/matplotlib)

这篇关于Matplotlib AFM进口速度极慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆