导入matplotlib包是出现各种错误,解决一个又出现一个。比如:module ‘matplotlib’ has no attribute ‘get_data_path’,No module named ‘pyparsing’,cannot import name ‘get_versions’ from ‘matplotlib._version’等等。在网上大多数都是重新安装matplotlib包,然而也没有解决。

这个错误可能是由于Matplotlib的版本不兼容导致的,与你Python版本或者其他包(numpy,scipy)版本不兼容问题。

解决方法:

1、在终端Anaconda Prompt(切换到运行Python的环境下),激活环境。

2、删除numpy,scipy,matplotlib包(最好是按顺序)。

pip uninstall numpy,pip uninstall numpy,pip uninstall matplotlib

3、重新安装numpy,scipy,matplotlib包(最好是按顺序)

利用清华镜像:

pip install numpy-i https://pypi.tuna.tsinghua.edu.cn/simple

pip install scipy-i https://pypi.tuna.tsinghua.edu.cn/simple

pip install matplotlib-i https://pypi.tuna.tsinghua.edu.cn/simple

最后重新导入matplotlib,导入成功!!!(花了我一小时导入