环境:Ubuntun14.04LTS +Anaconda4.2+tensorflow1.2+pycharm community.3.3
运行.py文件时,1.出现ImportError: No module named matplotlib.pyplot
2.
出现modulenotfounderror:no module namedmatplotlib._path"
原因详解:
第一种情况,出现ImportError: No module named matplotlib.pyplot
原因:未安装matplotlib包
对应解决办法:终端terminal输入sudo apt-get intall python-matplotlib
或者 pip install matplotlib
第二种情况,出现modulenotfounderror:no module namedmatplotlib._path"
原因分析:Anaconda,它直接将所有能用到的或者用不到的包都导入进来,有可能已经含有matplotlib包;
而pycharm里面已经装了matplotlib包;
故python编译器无法识别两个版本的matplotlib包,需要删除其中一个并将另一个包放在Anaconda目录下面即可解决问题
使用pip install matplotlib查看matplotlib包的位置(如果已经安装了matplotlib包):会显示已经安装成功和你所安装的位置
(比如我的属于第一种情况,直接安装即可,安装完成可以通过pip install matplotlib 查看其安装路径)