[英]ImportError: cannot import name 'QColorConstants' from 'PyQt5.QtGui
i have Ubuntu 20.04.4 LTS python 3.8.10 64bits and i have this error: Traceback (most recent call last): File "", line 6, in ImportError: cannot import name 'QColorConstants' from 'PyQt5.QtGui' (/usr/lib/python3/dist-packages/PyQt5/QtGui.abi3.so)我有 Ubuntu 20.04.4 LTS python 3.8.10 64 位,我有这个错误:回溯(最近一次通话):导入错误中的文件“”,第 6 行:无法从“PyQt5.QtGui”导入名称“QColorConstants”(/ usr/lib/python3/dist-packages/PyQt5/QtGui.abi3.so)
i found this in order to update pyqt from 5.14: https://askubuntu.com/questions/1383590/is-it-possible-to-install-python3-pyqt5-5-15-on-ubuntu-20-04我发现这个是为了从 5.14 更新 pyqt: https://askubuntu.com/questions/1383590/is-it-possible-to-install-python3-pyqt5-5-15-on-ubuntu-20-04
But still it doesn't work但还是不行
>>> from PyQt5.QtCore import PYQT_VERSION_STR
>>> PYQT_VERSION_STR
'5.15.2'
I ran these commands (the typical one) in a virtual environment of python 3.8.10 in Ubuntu 20.04.4:我在 Ubuntu 20.04.4 的 python 3.8.10 虚拟环境中运行了这些命令(典型的):
pip install pyqt5
And it installed version 5.15.6
.它安装了版本
5.15.6
。 I recommend to uninstall your package first with我建议先卸载你的 package
pip uninstall pyqt5
and then the pip install command.然后是 pip 安装命令。 Alternatively.
或者。 if you want a specific version of the package (I assume 5.15.5) you can just force it during the installation with
如果您想要特定版本的 package(我假设是 5.15.5),您可以在安装过程中强制使用它
pip install pyqt5==5.15.5
Anyway, with version 5.15.6
I can do your import.不管怎样,有了
5.15.6
版我可以做你的导入。
However, I got your error但是,我得到了你的错误
ImportError: cannot import name 'QColorConstants' from 'PyQt5.QtGui.py"
Traceback (most recent call last):
File "path-here" - ImportError: cannot import name 'QColorConstants' from 'PyQt5.QtGui.py", line 2, in <module>
from pyqt5.QtCore import PYQT_VERSION_STR
ModuleNotFoundError: No module named 'pyqt5'
when I tried当我试过
from pyqt5.QtCore import PYQT_VERSION_STR
print(PYQT_VERSION_STR)
instead of代替
from PyQt5.QtCore import PYQT_VERSION_STR
print(PYQT_VERSION_STR)
which gives the correct output. Check if you import somewhere pyqt5
instead of PyQt5
.这给出了正确的 output。检查您是否导入某处
pyqt5
而不是PyQt5
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.