解决PyQt编译资源文件时的TypeError错误

转自 http://www.kder.info/pyqt-resource-typeerror-solution.html

今天用 pyrcc4 编译qrc资源文件时遇到了如下错误:

Traceback (most recent call last):
 File "F:/Work/pps-qt/PPS_QT.py", line 20, in <module>
   import pps_qrc
 File "F:/Work/pps-qt/pps_qrc.py", line 78, in <module>
   qInitResources()
 File "F:/Work/pps-qt/pps_qrc.py", line 73, in qInitResources
   QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_
resource_data)
TypeError: qRegisterResourceData(int, str, str, str): argument 2 has unexpected type 'str'

奇怪,以前用着还好,怎么突然就不行了,Google一下,发现stackoverflow上有人提到:

pyrcc generates Python 2.x code by default.

Try regenerating your resource files using pyrcc with flag '- py3 '

错误原因:

原来我最近把Python升级到了3.1,而pyrcc默认生成的代码是Python2.x的,从而造成了不兼容。

解决办法:

把编译命令后面加上-py3 ,如

pyrcc4 .exe -py3 some.qrc -o someqrc.py

果然成功了,问题解决。附参考网址:

http://stackoverflow.com/questions/1619574/pyqt-problems-using-pyqts-resource-system/1658244#1658244

你可能感兴趣的:(python,struct,Module,File,qt,import)