Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named PyQt5.sip

After upgrading to python-pyqt5 5.12-2 I get this error when I try to import from 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?

like image 590
Holderekt Avatar asked Mar 10 '19 11:03

Holderekt


3 Answers

As suggested here pyuic5 - ModuleNotFoundError: No module named PyQt5.sip

Try uninstalling and re-installing all PyQt related libraries:

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)

like image 98
Tadeu Sampaio Avatar answered Nov 10 '22 10:11

Tadeu Sampaio


The reason is a backward incompatible change in PyQt-5.11

In geoptics this fix works on old and new versions:

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
like image 32
ederag Avatar answered Nov 10 '22 10:11

ederag


If you're building sip and PyQt5 from source using make files, make sure to check 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:

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.

like image 3
Mikhail Korobov Avatar answered Nov 10 '22 11:11

Mikhail Korobov