问题
导入下面的包后
%matplotlib inline
import torch
import torchvision
from torch import nn
from d2l import torch as d2l
出现下面几个报错
cannot import name 'mplDeprecation' from 'matplotlib._api.deprecation' (D:\environment\work_tool\anaconda3\envs\d2l\lib\site-packages\matplotlib\_api\deprecation.py
cannot import name 'colors' from 'matplotlib'
module 'matplotlib' has no attribute 'rcParams'
解决办法
本来一直认为是matplotlib的版本问题,换了好多个版本但一直没用,最后从头把所有常用的包删了重装环境时发现问题,在重装d2l包后出现以下报错
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
d2l 0.17.6 requires numpy==1.21.5, but you have numpy 1.22.4 which is incompatible.
执行安装后出现
ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: 'D:\\environment\\work_tool\\anaconda3\\envs\\d2l\\Lib\\site-packages\\numpy\\core\\_multiarray_tests.cp39-win_amd64.pyd'
Consider using the `--user` option or check the permissions.
根据提示加上--user后解决
pip install numpy==1.22.4 --user
最后将numpy退回1.21.5,但是还是存在不兼容的情况,不过至少想运行的代码能跑起来了。
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
scipy 1.13.1 requires numpy<2.3,>=1.22.4, but you have numpy 1.21.5 which is incompatible.
从结果来看应该是numpy的库有问题,但报错一直报的是matplotlib,很奇怪,总之要是发现环境报错不如直接按照书上的要求重装一下d2l看看到底是哪里有问题。
pip install d2l==0.17.6