TypeError
解决问题:
TypeError:draw_networkx_nodes() got an unexpected keyword argument ‘with_labels’
解决思路:
类型错误:draw_network_nodes()得到意外的关键字参数’with_labels’
解决方法:
删掉‘with_labels’即可
AttributeError
解决问题:
AttributeError: module ‘community’ has no attribute ‘best_partition’
解决方法:
pip install python-louvain
解决问题:
AttributeError: ‘NoneType’ object has no attribute ‘shape’
问题描述:
import cv2
img = cv2.imread('a')
print(img.shape)
解决方法:
找错时发现,img = cv2.imread(‘a.jpg’)的返回值img为none,故根本就没有成功读取图片,网上的解决方法都是说绝对路径都中文或者是用了单斜杠(\是转义字符),但自己两种问题都不存在,最后发现路径名中的文件名没有后缀,或者说文件名加后缀不对应。
import cv2
img = cv2.imread('a.jpg')
print(img.shape)
TypeError
在跑K-means算法时遇到
解决问题:
TypeError: unsupported operand type(s) for -: ‘map’ and ‘map’
解决思路:
fltLine = map(float, curLine)
在python2中返回的是一个list类型数据,而在python3中该语句返回的是一个map类型的数据(即是地址)故需要将数据类型转换为列表型。
解决方法:
fitLine = list(map(float,curLine))
ValueError
紧跟着又出现值错误
解决问题:
ValueError: could not convert string to float: ‘1.658985 4.285136’
解决方法:
curLine = line.strip().split(’\t ‘)改成curLine = line.strip().split(’ ')
链接
AttributeError
解决问题:
AttributeError: module ‘string’ has no attribute ‘atoi’
解决思路:
atoi函数是将str转化为int,python3中不支持,而用int()转换在python2,python3中都支持。
解决方法:
string.atoi(your_str)替换成int(your_str)
链接
TypeError
解决问题:
TypeError:dict_keys’ object is not subscriptable
具体问题:
dict1 = {1:1}
dict2 = {1:2}
if (dict1.values()[0] < dict2.values()[0]):
print(dict1)
解决思路:
object is not subscriptable意思是对象不应该具有下标,原因是dict的value()和key()返回的并不是一个真正的数组,所以,处理方法也很简单,只需要用list()强制转换一下即可。
解决方法:
dict1 = {1:1}
dict2 = {1:2}
if (list(dict1.values())[0] < list(dict2.values())[0]):
print(dict1)