", line 1, in File "/usr/l...">

ImportError: cannot import cbook name

>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 123, in <module>
    from . import cbook
ImportError: cannot import name cbook

I have not found a solution, can anyone help?

+16
source share
2 answers

1. Try updatingmatplotlib

python -m pip install -U matplotlib

2. Try reinstallingmatplotlib

python -m pip uninstall matplotlib
python -m pip install -U matplotlib

What displays the following snippet on the console?

python -c "import matplotlib"
+17
source

I ran into this problem today due to bad addiction.

If you have backports.shutil_get_terminal_sizeand backports.functools_lru_cacheinstalled, you may encounter this.

Matplotlib has a fragile workaround for looping imports:

# cbook must import matplotlib only within function
# definitions, so it is safe to import from it here.
from . import cbook

Prior to PR # 10483 , matplotlib depended on backports.functools_lru_cache.

, ipython backports.shutil_get_terminal_size, .

, :

>>> import backports
<module 'backports.shutil_get_terminal_size' from '/Users/whughes/miniconda2/envs/scratch/lib/python2.7/site-packages/backports/shutil_get_terminal_size/__init__.pyc'>
>>> >import backports.functools_lru_cache
ImportError: No module named functools_lru_cache

backports.shutil_get_terminal_size , , backports.foo .

matplotlib , sys.path, backports.functools_lru_cache , .

, backports.shutil_get_terminal_size.

+7

Source: https://habr.com/ru/post/1679586/


All Articles