使用matplotlib库时,会出现AttributeError: module 'matplotlib' has no attribute 'verbose'
问题。
在网上寻找解决方法时,总结了几种解决方法,可以逐一尝试。
方法一:卸载后重新安装
方法二:回滚到低版本
pip3 install --upgrade matplotlib==2.1.2
但是在回滚过程中,出现了新的问题ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
,对这个问题,大多数人的解决办法是更新两个包:
pip install --upgrade pip
pip install --upgradesetuptools
但更新两个包不一定能解决问题,还有人这样做-解决办法链接这里不细聊该问题。
方法三:修改库文件
根据提示出错的文件,进入最后一行提示的文件,进入文件:
from matplotlib.backend_bases import FigureManagerBase, ShowBase from matplotlib.backends.backend_agg import FigureCanvasAgg from matplotlib.figure import Figure
HOST = 'localhost'
PORT = os.getenv("PYCHARM_MATPLOTLIB_PORT")
PORT = int(PORT) if PORT is not None else None
PORT = PORT if PORT != -1 else None
index = int(os.getenv("PYCHARM_MATPLOTLIB_INDEX", 0))
rcParams = matplotlib.rcParams
verbose = matplotlib.verbose
出错在verbose=matplotlib.verbose这里
因为在Python3中matplotlib中是Verbose,注意:大写的V
(这里有两个verbose,我不确定改哪一个,我都尝试了一下,但是问题都没有得到解决)
方法四:Pycharm本身设置的问题
如果进行了一系列的操作之后,还是会有错误提示,那么可能不是你安装错了,也不是代码的问题,而是PyCharm的设置问题。
在File->settings->Tools->Python Scientific中,把“Show plots in toolwindow”前面的对号取消掉,然后重新启动PyCharm就可以了。
(我是通过这个方法解决的)
以上所有方法的参考链接如下:
http://www.mamicode.com/info-detail-2219568.html
https://www.cnblogs.com/BlogOfMr-Leo/p/8546901.html