[英]No module named PyQt5.sip
After upgrading to python-pyqt5 5.12-2 I get this error when I try to import from QtWidgets升级到 python-pyqt5 5.12-2 后,当我尝试从 QtWidgets 导入时出现此错误
from PyQt5.QtWidgets import *
Error:错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.sip'
Any idea on how can I solve this issue?关于如何解决这个问题的任何想法?
The reason is a backward incompatible change in PyQt-5.11原因是PyQt-5.11 向后不兼容的变化
In geoptics
this fix works on old and new versions:在
geoptics
此修复适用于旧版本和新版本:
try:
# new location for sip
# https://www.riverbankcomputing.com/static/Docs/PyQt5/incompatibilities.html#pyqt-v5-11
from PyQt5 import sip
except ImportError:
import sip
As suggested here pyuic5 - ModuleNotFoundError: No module named PyQt5.sip正如这里建议的那样 pyuic5 - ModuleNotFoundError: No module named PyQt5.sip
Try uninstalling and re-installing all PyQt related libraries:尝试卸载并重新安装所有 PyQt 相关库:
pip uninstall PyQt5
pip uninstall PyQt5-sip
pip uninstall PyQtWebEngine
Then install them again, this will fix:然后再次安装它们,这将修复:
ModuleNotFoundError: No module named 'PyQt5.sip'
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'
PPS.:If you got problems uninstalling the libraries, go to your Python folder, like C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Python\\Python<PYTHON-VERSION>\\Lib\\site-packages
and manually delete the PyQt folders, them uninstall everything and install again (Make sure you have the latest Python version and upgraded your pip too) PPS。:如果在卸载库时遇到问题,请转到 Python 文件夹,例如
C:\\Users\\<USERNAME>\\AppData\\Local\\Programs\\Python\\Python<PYTHON-VERSION>\\Lib\\site-packages
并手动删除PyQt 文件夹,它们会卸载所有内容并重新安装(确保您拥有最新的 Python 版本并升级了您的 pip)
If you're building sip and PyQt5 from source using make files, make sure to check PyQt5 install docs .如果您使用 make 文件从源代码构建 sip 和 PyQt5,请确保检查 PyQt5 install docs 。 In particular,
特别是,
Note
笔记
When building PyQt5 v5.11 or later you must configure SIP to create a private copy of the sip module using a command line similar to the following:
在构建 PyQt5 v5.11 或更高版本时,您必须配置 SIP 以使用类似于以下内容的命令行创建 sip 模块的私有副本:
python configure.py --sip-module PyQt5.sip
python configure.py --sip-module PyQt5.sip
If you already have SIP installed and you just want to build and install the private copy of the module then add the --no-tools option.
如果您已经安装了 SIP 并且您只想构建和安装模块的私有副本,那么添加 --no-tools 选项。
You should add PyQt5.sip to hidden imports;您应该将 PyQt5.sip 添加到隐藏的导入中; that should solve the issue.
这应该可以解决问题。
I repaired this problem我修复了这个问题
This problem occurred when upgrading pyqt5 version 5.15.0升级pyqt5 5.15.0版本时出现这个问题
There was no problem when I reverted to the previous version.当我恢复到以前的版本时没有问题。
I have python -V: 3.7.4我有 python -V: 3.7.4
PYQT5 5.14.1 and PYSIDE 5.14.1 works fine PYQT5 5.14.1 和 PYSIDE 5.14.1 工作正常
In addition to the answer provided by Tadeu ( https://stackoverflow.com/a/58880976/12455023 ) I would also suggest checking version of your libraries to make sure that they match.除了 Tadeu ( https://stackoverflow.com/a/58880976/12455023 ) 提供的答案之外,我还建议检查您的库的版本以确保它们匹配。
Use pip show <library_name>
使用
pip show <library_name>
This will help you to make sure that no earlier installation is conflicting with your current installation.这将帮助您确保之前的安装不会与您当前的安装发生冲突。
In place of library_name use PyQt5
, PyQt5-sip
, PyQtWebEngine
.代替 library_name 使用
PyQt5
, PyQt5-sip
, PyQtWebEngine
。 If any of them is present in the system, then use pip uninstall <library_name>==<version_number>
to remove that library.如果系统中存在其中任何一个,则使用
pip uninstall <library_name>==<version_number>
删除该库。
Once you made sure that no other versions of these libraries are there, then you can reinstall the preferred version of that library.一旦确定没有这些库的其他版本,就可以重新安装该库的首选版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.