From matplotlib.font_manager, ImportError: cannot import name get_font #8168

Closed
premier424 opened this Issue Feb 27, 2017 · 5 comments

Comments

Projects
None yet
4 participants

I met an error when using pyplot in matplotlib. In matplotlib/backends, there is from matplotlib.font_manager import findfont get_font. When I build and run the code, there shows the error:
ImportError: cannot import name get_font

From current documentation of font_manager on matplorlib website, there is no get_font module introduced but it was used in the source code of matplotlib. There are few similar errors reporting online so I'm wondering is this a version problem of python or matlibplot but I'm not quite clear about this. Please give me some advices. The python version is 2.7.6 and matplotlib version is 2.0.0. Thanks.

Owner

tacaswell commented Feb 28, 2017

Can you please include the full traceback? How did you install matplotlib?

jtexnl commented Mar 12, 2017

I've had the same problem. Here's my traceback:

>>> plt.savefig('figure_1a.png')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/site-packages/matplotlib/pyplot.py", line 697, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/matplotlib/figure.py", line 1565, in savefig
    kwargs.setdefault('facecolor', rcParams['savefig.facecolor'])
  File "/usr/local/lib/python3.4/site-packages/matplotlib/backend_bases.py", line 2139, in print_figure
    format = self.get_default_filetype()
  File "/usr/local/lib/python3.4/site-packages/matplotlib/backend_bases.py", line 2071, in _get_output_canvas
    
  File "/usr/local/lib/python3.4/site-packages/matplotlib/backend_bases.py", line 137, in get_registered_canvas_class
    if cbook.is_string_like(backend_class):
  File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/usr/local/lib/python3.4/site-packages/matplotlib/backends/backend_agg.py", line 35, in <module>
    from matplotlib.font_manager import findfont, get_font
ImportError: cannot import name 'get_font'

jtexnl commented Mar 12, 2017

FWIW, I tried re-jiggering my the base files that are showing problems, but it didn't work and I don't know the code well enough to make my own correction. From what I can gather, a lot of functions in font_manager are referencing a get_font function that's not defined in the script.

Owner

tacaswell commented Mar 12, 2017

get_font is defined here:

https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/font_manager.py#L1370

How did you install mpl?

It looks like you have crossed versions of python, looking at these two lines:

...
  File "/usr/local/lib/python3.4/site-packages/matplotlib/backend_bases.py", line 137, in get_registered_canvas_class
    if cbook.is_string_like(backend_class):
  File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
...

it seems to be hitting system python and then hitting a version of python installed via brew.

Contributor

anntzer commented Apr 15, 2017

Closing as @tacaswell suggests a reasonable source for the problem (crossed python versions). Feel free to ask for a reopening.

anntzer closed this Apr 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment