matplotlib 库安装教程

matplotlib 库安装教程


使用命令行安装
1、打开命令行窗口
2、输入python -m pip install -U pip setuptools 进行升级
matplotlib 库安装教程
3、输入 python -m pip install matplotlib 进行自动的安装,系统会自动下载安装包
matplotlib 库安装教程
4、检查是否成功:在命令行窗口中输入python,在输入 import matplotlib ,如图所示,没有报错即为成功
matplotlib 库安装教程

出错处理:大部分按照上述操作都能成功导入库,有的会出现错误,窗口出现一大堆红色的Exception
matplotlib 库安装教程
这时候我们留意到这句话:socket.timeout:The read operation timed out
matplotlib 库安装教程
超时了
当pip的镜像源是国外时,经常遇到‘time out’,我们只需要把源地址改为国内可用的镜像网站就可以避免这个问题

如果在国内镜像网站搜索不到该软件或者包,可以换个镜像网站重新下载。下面为部分国内可用的镜像网站:

Python官方:https://pypi.python.org/simple
v2ex:http://pypi.v2ex.com/simple
阿里云:http://mirrors.aliyun.com/pypi/simple
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple
中国科学院:http://pypi.mirrors.opencas.cn/simple
douban:http://pypi.douban.com/simple

如果你经常需要用到pip安装各种模块,建议你更改一下pip源临时使用可以在使用pip的时候加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent,这样就会从清华这边的镜像去安装gevent库所以你应该执行

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

来安装matplotlib库

matplotlib 库安装教程
成功!
当然,也有笨的方法,它是因为网络等问题导致的timeout(超时),那你就可以把timeout的判断时间变长,那就可以在漫长的等待中成功安装了。。。

执行命令

pip --default-timeout=100 install -U matplotlib

如果有问题解决不了,扫一扫关注我,给你解决
里面还有各种经验分享,学习资料,等你哦~
matplotlib 库安装教程