我刚刚在 OpenSUSE leap 上使用 python 3.6.3 在 pyenv virtualenv 中构建了 PyQt5,构建很顺利,但是当我导入时
>>> from PyQt5 import QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: PyCapsule_GetPointer called with incorrect name
我可以导入PyQt5,但是我不能使用它下面的模块
>>> import PyQt5
>>> PyQt5.QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'PyQt5' has no attribute 'QtCore'
我读过 here原因可能是系统上的另一个 sip,例如 PyQt4 安装,我尝试从包管理器中卸载 PyQt4,但没有帮助。
我不知道该怎么做,有什么想法吗?
如果我安装 python3-qt5 包并使用系统 python 就可以了
编辑:
我在 OpenSUSE Leap 15 的另一台机器上遇到了与 PyQt4 相同的问题,解决方案是配置 sip:
python configure.py --sip-module PyQt4.sip --no-dist-info --no-tools
如 PyQt4 doc 中所述
最佳答案
好吧,这实际上很简单,如文档中所述(PyQt4,PyQt5),SIP 必须使用 --sip-module 选项进行配置,因此对于 PyQt5,我做了:
python configure.py --sip-module PyQt5.sip --no-tools
对于 PyQt4:
python configure.py --sip-module PyQt4.sip --no-tools
这适用于 PyQt >= 4.12.2 和 PyQt >= 5.11
编辑: PyQt5 现在有所谓的 PyQt-builder,参见 PyQt5 doc
关于linux - PyQt5错误 "PyCapsule_GetPointer called with incorrect name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51693993/