How to solve this Python AttributeError: module 'matplotlib' has no attribute 'get_data_path' (in JupyterLab 3.0>=)

How to solve this Python AttributeError: module 'matplotlib' has no attribute 'get_data_path' (in JupyterLab 3.0>=)

今天(2​​021年3月30日)升级matplotlib和seaborn包

但是,之后,我无法导入 matplotlib 和 seaborn 包。

每当我尝试导入 matplotlib 或 seaborn 时, 我收到如下错误消息。

我该如何解决这个问题?

(我用的是JupyterLab 3.0)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-33-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt

C:\dev\anaconda3\lib\site-packages\matplotlib\__init__.py in <module>
    819 # triggering resolution of _auto_backend_sentinel.
    820 rcParamsDefault = _rc_params_in_file(
--> 821     cbook._get_data_path("matplotlibrc"),
    822     # Strip leading comment.
    823     transform=lambda line: line[1:] if line.startswith("#") else line,

C:\dev\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in _get_data_path(*args)
    478     if opened:
    479         with fh:
--> 480             yield fh
    481     else:
    482         yield fh

AttributeError: module 'matplotlib' has no attribute 'get_data_path'

这些类型的错误是版本冲突的典型错误,尤其是在您最近升级的情况下。

一个常见的错误是只升级一个软件包并期望其他一切都能继续工作。某些版本的库仅与某些版本的其他库等兼容。现实情况是,您必须找到 所有库作为一个整体的工作组合。从你的例子中不可能知道出了什么问题,但我假设你还必须升级 maptplotlib 依赖项,可能还有它们的依赖项。

如果您对这些库不是很熟悉,追查起来可能会很棘手,因此您最好通过 pip 或其他一些依赖项感知包管理器简单地重新安装所有内容。