Ped*_*dru 5 linux python-3.x python-sip pyqt5
我刚刚在 OpenSUSE 飞跃上使用 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
Run Code Online (Sandbox Code Playgroud)
我可以导入PyQt5,但是我不能使用它下面的模块
>>> import PyQt5
>>> PyQt5.QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'PyQt5' has no attribute 'QtCore'
Run Code Online (Sandbox Code Playgroud)
我在这里读到原因可能是系统上的另一个 sip,例如 PyQt4 安装,我尝试从包管理器中卸载 PyQt4,但没有帮助。
我不知道该怎么办,有什么想法吗?
如果我安装 python3-qt5 包并使用系统 python 它工作
编辑:
我在 OpenSUSE Leap 15 上的另一台机器上使用 PyQt4 遇到了同样的问题,解决方案是配置 sip:
python configure.py --sip-module PyQt4.sip --no-dist-info --no-tools
Run Code Online (Sandbox Code Playgroud)
好的,这实际上非常简单,正如文档(PyQt4,PyQt5)中所述,必须使用该--sip-module选项配置 SIP,所以对于 PyQt5 我做了:
python configure.py --sip-module PyQt5.sip --no-tools
Run Code Online (Sandbox Code Playgroud)
对于 PyQt4:
python configure.py --sip-module PyQt4.sip --no-tools
Run Code Online (Sandbox Code Playgroud)
这适用于 PyQt >= 4.12.2 和 PyQt >= 5.11
编辑:PyQt5 现在有所谓的 PyQt-builder,请参阅PyQt5 文档