文章目录

1、module ‘sklearn’ has no attribute ‘datasets’

将 import sklearn 改成了 from sklearn import datasets 就好了

看网上的博客好像是因为安装的模块版本不对

2、module ‘seaborn’ has no attribute ‘load_dataset’

我把当前文件命名成了seaborn.py,应该是起了冲突,改名后就好了

3、fit_transform() missing 1 required positional argument: ‘X’

因为 StandardScaler.fit_transform() 中的 StandardScaler 后面没有加括号

改成StandardScaler().fit_transform()就好了

4、ValueError: query data dimension must match training data dimension

查询数据维度必须与训练数据维度匹配

注意检查传入参数的数据维度

5、unindent does not match any outer indentation level

缩进问题,可能会有看不到的空格等字符

解决方法:

①将代码放到notepad++中,点击“视图”——>“显示符号”——>“显示空格与制表符”

②此时就可以看到代码中所有的空格和制表符了,将代码左边的空格全部删去,并用制表符代替即可

6、inconsistent use of tabs and spaces in indentation

解决方法同上

7、GraphViz’s executables not found

链接:https://blog.csdn.net/qq_42700429/article/details/82927961

加上下面两行代码即可

import os     
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'

8、invalid literal for int() with base 10

int() 只能将字符型的数字转化为整型,如果传入的参数不是字符数字,就会报错

9、‘gbk’ codec can’t decode byte 0x93 in position 344: illegal multibyte sequen

要处理的字符串本身不是gbk编码,但是却以gbk编码去解码

在open(file, encoding=‘utf-8’)中修改解码方式

10、‘str’ object has no attribute ‘decode’、

链接:https://blog.csdn.net/qq_38890412/article/details/86591294

11、python下cv.waitKey无响应原因

要先点击一下弹出的窗口,在窗口输入

12、sequence too large; cannot be greater than 32

直接使用np.array()

13、UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.

在开头加上:

import matplotlib; matplotlib.use('TkAgg')

链接:https://blog.csdn.net/u011561613/article/details/100094794

14、error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv

filename 路径不能有中文

15、PIL库使用resize函数后图片大小不变

https://www.cnblogs.com/xyzluck/p/13033897.html

注意resize不会改变原图的大小,它是有返回值的,需要用一个变量来接收

16、SyntaxError: name ‘xxxxx’ is used prior to global declaration

在 global 声明之前就使用变量

17、‘dict’ object has no attribute ‘has_key’

改成如下的形式

if key in dict:

18、ValueError: could not convert string to float

https://blog.csdn.net/weixin_35436966/article/details/105941671

不能将string转化为float

在处理数据没有处理空值时经常出现这个错误

19、RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available()

https://www.codeleading.com/article/24872188149/

出错语句:

torch.load(model_file)

改为:

model = torch.load(model_path, map_location='cpu')

20、ValueError: Expected 2D array, got 1D array instead

使用sklearn模型预测数据时报出了这个错误,搜了一下发现在sklearn中需要使用二维数据

如果只有一条数据,需要在数据外面再套一层列表

21、KeyError: ‘A’

字典查找的键 A 不存在

22、IndexError: Caught IndexError in DataLoader worker process 0.

把num_worder设为0

23、RuntimeError: Dataset not found or corrupted. You can use download=True to download it

本地没有数据集,使用 download=True 进行下载即可

24、IndexError: too many indices for tensor of dimension 0

https://ask.csdn.net/questions/1061401

把transforms.Normalize((0.1307),(0.3081))改为transforms.Normalize((0.1307,),(0.3081,))

25、AssertionError: Torch not compiled with CUDA enabled

https://blog.csdn.net/weixin_38324954/article/details/109630508

加一句:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

26、SyntaxError: unexpected EOF while parsing

代码的最后漏掉了半个括号

27、AttributeError: module ‘numpy.random’ has no attribute ‘default_rng’

numpy版本不适配

pip uninstall numpy
pip install numpy

28、UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xa1 in position 6: invalid start byte

https://blog.csdn.net/weixin_40769885/article/details/82288553

29、AttributeError: type object ‘Word2Vec’ has no attribute ‘LineSentences’

https://vimsky.com/examples/detail/python-method-gensim.models.word2vec.LineSentence.html

导入的方法不对

from gensim.models.word2vec import LineSentence

30、SyntaxError: invalid character in identifier

注意可能有中文字符

31、ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

https://www.cnblogs.com/christy99cc/p/11294636.html

32、TypeError: Invalid shape (3, 32, 32) for image data

http://www.juzicode.com/archives/3502

imshow()方法显示numpy数组,数组要么是2维数组(灰度图),要么是3维数组(彩色图)。如果是3维数组,其第3维必须是3或者4,正好对应了3通道或者4通到彩色图像

33、NoneType : object has no attribute shape

导入图片的路径不正确

34、ImportError: cannot import name xxx from

我这次是因为导入包的名字写错了

35、ImportError: No module named **

路径有问题,注意路径应该是main.py文件对应的路径

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐