错误:从matplotlib导入_png导入错误:无法从'matplotlib'导入名称'_png'(C:\\ Garden \ lib \ site-packages \ matplotlib \ __ init__.py)

时间:2020-08-27 11:28:02

标签: python matplotlib kivy

我想使用garden.matplotlib.FigureCanvas,但每次遇到同样的问题。我安装了matplotlibgardenkivy(分开)。除matplotlib.backend_kivyagg之外,所有库安装工作。
我从kivy下载了一个文件进行测试(https://github.com/kivy-garden/garden.matplotlib)。 错误在这里:

-----------------------------------------------------------------------------------   
Traceback (most recent call last):
   File "C:/Users/alidi/OneDrive/Desktop/Garden/garden.matplotlib/garden.matplotlib-master/examples/test_backend.py", line 10, in <module>
     from kivy.garden.matplotlib.backend_kivyagg import FigureCanvas,\
   File "C:\Users\alidi\Desktop\Data_analysis_book_\Garden\lib\site-packages\kivy\garden\__init__.py", line 180, in load_module
     return self._load_module(fullname, moddir)
   File "C:\Users\alidi\Desktop\Data_analysis_book_\Garden\lib\site-packages\kivy\garden\__init__.py", line 183, in _load_module
     mod = imp.load_module(fullname, None, moddir,
   File "C:\Users\alidi\AppData\Local\Programs\Python\Python38-32\lib\imp.py", line 244, in load_module
     return load_package(name, filename)
   File "C:\Users\alidi\AppData\Local\Programs\Python\Python38-32\lib\imp.py", line 216, in load_package
     return _load(spec)
   File "C:\Users\alidi\.kivy\garden\garden.matplotlib\__init__.py", line 1, in <module>
     from kivy.garden.matplotlib.backend_kivy import FigureCanvasKivy,\
   File "C:\Users\alidi\.kivy\garden\garden.matplotlib\backend_kivy.py", line 256, in <module>
     from matplotlib import _png
 ImportError: cannot import name '_png' from 'matplotlib' (C:\Users\alidi\Desktop\Data_analysis_book_\Garden\lib\site-packages\matplotlib\__init__.py)

Process finished with exit code 1

1 个答案:

答案 0 :(得分:1)

python 3.7 有同样的问题,kivy==2.0.0,kivy-garden==0.1.4,matplotlib==3.4.1。 降级 matplotlib 解决了问题:

pip install matplotlib==3.1.1