Python2.6-Python3.6
Error1:
TypeError: qRegisterResourceData(int, str,str, str): argument 2 has unexpected type 'str'
设置pyrrc的外部工具:
重新对qrc生成py文件。
Error2:
NameError: name 'codecs' is not defined
将 import codecs删除。
Error3:
TypeError: an integer is required (got typestr)
将open的第三个参数删除。
Error4:
NameError: name 'unicode' is not defined
Unicode修改为str。
Error5:
AttributeError: 'str' object has noattribute 'trimmed'
将.trimmed直接去掉即可。
Error6:
TypeError: unhashable type:'QListWidgetItem'。
要保证hash的正确性,作为key的对象就不能变。在Python中,字符串、整数等都是不可变的,因此,可以放心地作为key。而list是可变的,就不能作为key。
>>> key = [1, 2, 3]
>>> d[key] = 'a list'
Traceback (most recent call last): File"<stdin>", line 1, in <module>
TypeError: unhashable ty
List不能作为key
将item后加入.text(),来获得其选择的选项,再加个Int(item.text())
Error7:图片因为格式问题读取不正确
原程序所采用的方式为以二进制方式直接读取,这种读取方式导致的问题是无法读取jpg、jpeg文件。因此直接改变代码结构。
改变如下(1305- LoadFile函数):
原:
# # Load image:
# # read data first and store forsaving into label file.
# self.imageData = read(filename,None)
# self.labelFile = None
# image = QImage.fromData(self.imageData)
改正为:
else:
vis = cv2.imread(filename)
image_height, image_width,image_depth = vis.shape
QIm = cv2.cvtColor(vis,cv2.COLOR_BGR2RGB) # opencv读图片是BGR,qt显示要RGB,所以需要转换一下
image = QImage(QIm.data, image_width, image_height, # 创建QImage格式的图像,并读入图像信息
image_width * image_depth,
QImage.Format_RGB888)
Error8:界面进行改变后,无法改变
会生成一个pkl文件,直接把这个文件删除即可。
Error9:
FileNotFoundError: [Errno 2] No such fileor directory: 'None\\setting_panel.xml'
单独打开一张图片时,难以保存,原因是有个默认的选项。
Error10:如何打包成exe文件
需要用到pyinstaller工具
在pycharm中设置pyinstaller外部工具(settings-tools-external tool):


用pyinstaller外部工具对Py文件使用,即会生成一个libs和build文件夹,只需要libs文件夹里的exe文件。
之后需要在自己安装的pyqt里找到这样的几个文件,放在platforms文件夹里。

Error11:
FileNotFoundError: [Errno 2] No such fileor directory: 'None\\remote_settings.xml'
解决方式1:在setting里设置好默认的存放地址
解决方式2:
Error12:
TypeError: write() argument must be str,not bytes
Error13:
ModuleNotFoundError: No module named'libs.pascalVocIO'
Error14:
TypeError: must be str, not int
一般都是print的时候出错,特别是在str+int 形式的输出时会报这个错。
Pyqt4-Pyqt5
Error1:
RuntimeError: the sip module implements APIv11.0 to v11.3 but the module requiresAPI v12.4
装了两个版本的PyQt会出现API版本的冲突,只能存在一个版本的PyQt,留下一个PyQt5即可。
Error2:
AttributeError: module 'PyQt5.QtGui' has noattribute 'QDialog'。
PyQt4的QtGui模块,在PyQt5中被拆分成三个模块:QtGui,QtPrintSupport和QtWidgets。
QDialog被移植到QtWidegets里。
Error3:
NameError: name 'QWidget' is not defined
NameError: name 'QDialogButtonBox' is notdefined
NameError: name 'QSpinBox' is not defined
NameError: name 'QMainWindow' is not defined
类似的问题都是因为QtGui的拆分,因此需要引用下一句:
from PyQt5.QtWidgetsimport *
Error4:
在引用qdarkstyle时,用到了app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False))。
这句会自动执行PyQt4下的代码,因此当单独存在一个PyQt5时会出错。
解决方式:
修改为:
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
Error5:
AttributeError: type object 'QObject' hasno attribute 'connect'
这里涉及一个PyQT4和PyQT5的槽函数连接区别的问题:
PyQt4中:
QObject.connect(
self.display_timer,
SIGNAL("timeout()"),
self.info_display)
修改为
self.display_timer.timeout.connect(self.info_display)
在PyQT5中将繁琐的QObject.connect槽函数信号连接形式已经废弃了,直接signal.connect(self.function)即可。
Error6:
AttributeError: 'QMouseEvent' object has noattribute 'posF'
将posf改为pos
Error7:
lxml.etree.XMLSyntaxError: Document isempty, line 1, column 1
xmltree = ElementTree.parse(self.filepath,parser=parser).getroot()
加载self.flilepath对应的xml文件,用.getroot()函数获得根节点。
#self.loadPascalXMLByFilename(xmlPath) 直接注释
Error8:
AttributeError: type object 'QObject' hasno attribute 'connect'
QtCore.QObject.connect(self.label_font_size_sl,QtWidgets.SIGNAL("valueChanged(int)"),
self.label_font_size_sp,QtWidgets.SLOT("setValue(int)"))
修改为
self.label_font_size_sl.valueChanged.connect(self.label_font_size_sp.setValue)
signal 与slot不能再写成QObject.connect的形式了。
Error9:
AttributeError: 'QListWidget' object has noattribute 'setItemSelected'
self.fileListWidget.setItemSelected(fileWidgetItem,True)
这个错误是在检测,直接去掉即可。
Error10:
AttributeError: 'QFileDialog' object has noattribute 'setConfirmOverwrite'
直接去掉了这句代码。
Error11:无法显示图片
文件框获取的的路径不对,qfile.open…这个函数返回了两个参数,不仅仅只有一个。
Error12:
TypeError: Can't convert 'NoneType' objectto str implicitly
这个错误出现在分类的文件夹打开的过程中。
这个的解决了,主要是先设置的模式,我们先设置检测,就没有问题了。
Error13:
打开单张照片后,无法正常打开文件夹了。
原因,一个print()函数的输出none与str相加,这样是不对的,将+号变成,即可。
Error14:
先打开一个dir,再打开一个单张图会出现以下的错误:
在重置函数中清filelist的表单。
Error15:
当第一次打开本软件的时候,单独打开一张图时,由于本软件有默认的存储路径,因此需要先添加默认路径。
Error16:
AttributeError: 'QWheelEvent' object has noattribute 'orientation'
Error17:
AttributeError: 'QWheelEvent' object has noattribute 'delta'
Delta----angleDelta
Error18:
滚筒有问题,处理方式

Error19:移植的软件出错
先给个默认的路径。
ERROR20:
RuntimeError: the sip module implements APIv11.0 to v11.3 but the module requiresAPI v12.4,版本冲突,在settings的project中重新导入interperater即可。
Error21:
xml.etree.ElementTree.ParseError: notwell-formed (invalid token): line 1, column 1
python3 与 python2的转码问题:
由 str转bytes:编码encode
Str=’test’
Bytes=str.encode(encoding=’utf-8’)
由bytes转str:解码decode
Bytes.decode()
22、os.mkidr(/../..)
注意这样的创建文件目录时会出错,因为不能跳级创建,当上级目录页不存在时,是无法创建的。
此时需要使用os.makedirs(../../)
23、
Pyqt如何弹出提示框:
24、AttributeError:'QListWidget' object has no attribute 'setItemSelected'
将self.labelList.setItemSelected(self.shapesToItems[shape], True)#设置指定shape对应的item
改为
self.shapesToItems[shape].setSelected(True)
25、
TypeError: unhashable type:'QListWidgetItem'
class HashableQListWidgetItem(QListWidgetItem):
def __init__(self, *args):
super(HashableQListWidgetItem,self).__init__(*args)
def __hash__(self):
#重写了魔方方法
return hash(id(self))
#返回可以hash的类型,id其实是该item对应的id。
#这样改写即可