解决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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值