当我导入garden.matplotlib包时,我收到错误提示: ImportError:无法从“ matplotlib.font_manager”导入名称“ weight_as_number”
我在命令提示符中使用了Python来逐步导入。我在garden.matplotlib导入行中发现错误。
系统:Windows 10,Python 3.7.0,Kivy 1.10.1
>>> import matplotlib
Backend TkAgg is interactive backend. Turning interactive mode on.
>>> matplotlib.use('module://kivy.garden.matplotlib.backend_kivy')
>>>from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
[INFO ] [Logger ] Record log in C:\Users\user.kivy\logs\kivy_18-10-03_7.txt
[INFO ] [Kivy ] v1.10.1
[INFO ] [Python ] v3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)]
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 20, in do_import
module = self.system_import(name, *args, **kwargs)
File "D:\Documents\venv\lib\site-packages\kivy\garden_init.py", line 100, in load_module
return self.load_module(fullname, moddir)
File "D:\Documents\venv\lib\site-packages\kivy\garden_init.py", line 104, in _load_module
('', '', imp.PKG_DIRECTORY))
File "C:\Python37-32\lib\imp.py", line 245, in load_module
return load_package(name, filename)
File "C:\Python37-32\lib\imp.py", line 217, in load_package
return load(spec)
File "C:\Users\user.kivy\garden\garden.matplotlib_init.py", line 1, in
from kivy.garden.matplotlib.backend_kivy import FigureCanvasKivy,
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\user.kivy\garden\garden.matplotlib\backend_kivy.py", line 257, in
from matplotlib.font_manager import weight_as_number
ImportError: cannot import name 'weight_as_number' from 'matplotlib.font_manager' (D:\Documents\venv\lib\site-packages\matplotlib\font_manager.py)
答案 0 :(得分:0)
Kivy仅支持旧版本的matplotlib。他们在matplotlib == 2.1.x之后的某个位置删除了weight_as_number函数,因此,如果您运行的是最新版本(3.0.0),它将无法正常工作。
尝试使用matplotlib == 2.1.2(我目前在此版本上,可以确认weight_as_number仍然存在)