No module named 'PyQt5.sip' - python

when I tried upgrading my PyQt version to 5.14.0 and later landed up importing the packages as:
from PyQt5 import QtGui, QtWidgets, QtCore
it throws an error:
runfile('C:/Users/Farhan Hyder .LAPTOP-R0TGSS2M/Desktop/BREATHE IN/Pred_WindowUI.py', wdir='C:/Users/Farhan Hyder .LAPTOP-R0TGSS2M/Desktop/BREATHE IN')
Traceback (most recent call last):
File "C:\Users\Farhan Hyder .LAPTOP-R0TGSS2M\Desktop\BREATHE IN\Pred_WindowUI.py", line 9, in <module>
from PyQt5 import QtGui, QtWidgets, QtCore
ModuleNotFoundError: No module named 'PyQt5.sip'
I also tried re-installing the libraries, but, unfortunately it didn't serve my purpose.

As per eyllanesc's comment, try updating pip:
python -m pip install --upgrade pip
Then try reinstalling pyqt5:
python -m pip install --upgrade pyqt5
It worked for me (though I actually used pip install --use-feature=2020-resolver pyqt5 for the new resolver).

Related

How to fix the error "QtWidgets.abi3.so Reason: image not found" in Python on Mac OS X Catalina?

I am trying to run my python 3.9 code. I am on Mac OS X Catalina 10.15
I get an error when importing some PyQt5 modules:
from PyQt5 import QtWidgets, QtCore, QtGui
From Pycharm, I get this error message:
Traceback (most recent call last):
File "/Volumes/GoogleDrive/My Drive/project/main.py", line 135, in <module>
from PyQt5 import QtWidgets, QtCore, QtGui
ImportError: dlopen(/usr/local/lib/python3.9/site-packages/PyQt5/QtWidgets.abi3.so, 2): Library not loaded: #rpath/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /usr/local/lib/python3.9/site-packages/PyQt5/QtWidgets.abi3.so
Reason: image not found
from terminal, I get this error:
dyld: loaded: <9D893D18-53D8-3C59-80F1-3E37DF41D246> /usr/local/lib/python3.9/site-packages/PyQt5/QtWidgets.abi3.so
dyld: unloaded: <9D893D18-53D8-3C59-80F1-3E37DF41D246> /usr/local/lib/python3.9/site-packages/PyQt5/QtWidgets.abi3.so
Traceback (most recent call last):
File "/Volumes/GoogleDrive/My Drive/project/main.py", line 135, in <module>
from PyQt5 import QtWidgets, QtCore, QtGui
ImportError: dlopen(/usr/local/lib/python3.9/site-packages/PyQt5/QtWidgets.abi3.so, 2): Library not loaded: #rpath/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /usr/local/lib/python3.9/site-packages/PyQt5/QtWidgets.abi3.so
Reason: image not found
I tried to upgrade pyqt5 with the command:
python3 -m pip install PyQt5 upgrade
but I get this error message:
Requirement already satisfied: PyQt5 in /usr/local/lib/python3.9/site-packages (5.15.4)
dyld: loaded: <F1258E44-15BC-3DBB-8563-B8703B358AD9> /usr/lib/libusrtcp.dylib
ERROR: Could not find a version that satisfies the requirement upgrade (from versions: none)
ERROR: No matching distribution found for upgrade
I. checked with :
python3 -m pip freeze
Here are all the PyQt5 modules I have:
PyQt3D==5.15.5
PyQt5==5.15.4
PyQt5-Qt5==5.15.2
PyQt5-sip==12.9.0
PyQt5-stubs==5.15.2.0
PyQt6==6.2.0
PyQt6-3D==6.2.0
PyQt6-Charts==6.2.0
PyQt6-DataVisualization==6.2.0
PyQt6-NetworkAuth==6.2.0
PyQt6-sip==13.1.0
PyQtChart==5.15.5
PyQtDataVisualization==5.15.5
PyQtNetworkAuth==5.15.5
PyQtPurchasing==5.15.5
PyQtWebEngine==5.15.5
PyQtWebEngine-Qt5==5.15.2
So I try with Homebrew :
brew install pyqt5
and I get this output:
Warning: pyqt#5 5.15.6 is already installed and up-to-date.
To reinstall 5.15.6, run:
brew reinstall pyqt#5
I search help on forum and I read some solution in my .zshrc file:
DYLD_LIBRARY_PATH="/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home:/usr/local/lib/python3.9/site-packages:/usr/local/lib/python3.9/site-packages/PySide2"
PATH="/usr/local/bin:/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home:/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home:/Users/alisa/.wdm/drivers/geckodriver/macos/v0.30.0:/Users/alisa/Android/cmdline-tools/latest/bin:/Users/alisa/Android/platform-tools:/bin:/opt/local/bin:/sbin:/usr/bin:/usr/local/Cellar/python#3.9/:/usr/local/Cellar/python#3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/bin/:/usr/local/Cellar/python#3.9/3.9.12_1/bin/:/usr/local/lib/python3.9/site-packages:/usr/local/opt/qt#/bin/:/usr/local/opt/qt#6/bin/:/usr/sbin/"
My file seems fine or did I forgot something?
Can anyone help me please to fix this issue?

ImportError: libOpenGL.so.0: cannot open shared object file: No such file or directory

When I am running my python program I am getting following error in my terminal.
Traceback (most recent call last):
File "./encryption.py", line 6, in <module>
from PySide6 import QtCore, QtWidgets, QtGui
ImportError: libOpenGL.so.0: cannot open shared object file: No such file or directory
How to solve it?
The import statements in my program are
#!/usr/bin/env python3
import sys
import random
import re
import pyAesCrypt
from PySide6 import QtCore, QtWidgets, QtGui
run the following command, to install libopengl0 library it required to run the code.
sudo apt install libopengl0 -y
The problem is a bug in PySide 6, which is apparently caused by a bug in Qt 6. Until that's fixed, you have to install OpenGL separately from installing PySide 6.
I installed it on Ubuntu 20.04 with this command:
sudo apt-get install freeglut3 freeglut3-dev

Unable to launch Spyder after installation of PyQt5

On installation of PyQt5 i'm unable to launch Spyder on Windows. When i tried to launch through the conda prompt, i get the following error,
File "C:\Users\sarshetty\Anaconda3\lib\site-packages\qtpy\__init__.py", line 132, in <module>
from PyQt5.QtCore import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore
RuntimeError: the sip module implements API v12.0 to v12.7 but the PyQt5.QtCore module requires API v12.8
I see the following for my sip and PyQt in the python terminal.
>>> import sip
>>> sip.SIP_VERSION_STR
'4.19.8'
>>> import PyQt5
>>> import PyQt5.Qt
>>> import PyQt5.QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: the sip module implements API v12.0 to v12.7 but the PyQt5.QtCore module requires API v12.8
I tried upgrading my sip, however that has not helped. Can anyone tell me what is happening and how i can resolve this.
I'm only guessing here but I think the error is referring to PyQt5-sip since the newest release is version 12.8.0
https://pypi.org/project/PyQt5-sip/
(Spyder maintainer here) Anaconda comes with its own version of PyQt5, so you don't need to install it by running pip install pyqt5 (which seems you did).
By doing that, you basically broke Anaconda and now you have to remove and reinstall it, sorry.
This fixed the issue for me
Uninstall the installed PyQt5 library with pip
pip3 uninstall pyqt5
Install PyQt5 with conda
conda install -c anaconda pyqt
Uninstall pyqt5(pip uninstall pyqt5) and then reinstall it version 5.11.3(pip install pyqt5==5.11.3)
After installing the new version it'll show an error msg but it will work anyways.
This has worked for me and my colleges.

PyQt5.QtWidgets module not found when pyqt is installed with Anaconda

I can import PyQt5 but I cannot import from PyQt5.QtWidgets when I install pyqt in a conda environment.
I've tried uninstalling and reinstalling with conda and that did not solve the problem.
If I install with pip in a regular virtual environment instead of with Anaconda then it works.
This is the code:
from PyQt5.QtWidgets import *
This is the error:
$ python main.py
Traceback (most recent call last):
File "main.py", line 1, in <module>
from PyQt5.QtWidgets import *
ModuleNotFoundError: No module named 'PyQt5.QtWidgets'
Turns out it was a path problem. I had installed Homebrew after Anaconda and /usr/local/bin was in front of $HOME/anaconda3/bin in $PATH, so Homebrew Python was being called instead of Anaconda Python.

Can't start spyder because of PyQt5.QtWebKitWidgets

I have a problem with spyder.
I just installed on this laptop Python 3.7 and Spyder, as I did on many others. However this time, it doesn't work.
I installed Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 with the installer. I changed the path to a custom path: C:\Python\Python37, I added the precompile library and I added the path to the environment.
The laptop was rebooted at that point.
Then I updated pip:
py -3.7 -m pip install --upgrade pip
And then I installed spyder:
py -3.7 -m pip install spyder
I then try to launch spyder with the file:
C:\Python\Pythno37\Lib\site-packages\spyder\app\start.py
I get the error:
ModuleNotFoundError: No module named 'PyQt5.QtWebKitWidgets'
PyQt5 is installed with version 5.12.
No clue why it doesn't work...
EDIT: The full error message:
It sugggest that the problem comes from qtpy. However, the corresponding file imports:
from . import PYQT5,PYSIDE2, PYQT4, PYSIDE, PythonQtError
# To test if we are using WebEngine or WebKit
WEBENGINE = True
if PYQT5:
try:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineWidgets import QWebEngineSettings
except ImportError:
from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView
from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings
WEBENGINE = False
The PyQt5.QtWebEngnieWidgets is correctly used.
I swapped Pyqt5 version from 5.12 to 5.11.2 with:
py -m pip install pyqt5==5.11.2
And now it works...
Three days ago I was playing around with Python, Mayavi and Jupyter Notebooks to create visualizations. This required to install PyQt5.
Due to constantly reaching memory errors, I've decided to test without using virtualenv's and installed the needed requirements on my local environment (which of course didn't solve).
After that, I was on my way to create visualizations using matplotlib and other Python libraries but can't launch Spyder from the Anaconda Navigator.
This is the error showing up, which is similar to yours
Traceback (most recent call last):
File "C:\Users\tiago\Anaconda3\lib\site-packages\qtpy\QtWebEngineWidgets.py", line 22, in
from PyQt5.QtWebEngineWidgets import QWebEnginePage
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\tiago\Anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\Users\tiago\Anaconda3\lib\site-packages\spyder\app\start.py", line 186, in main
from spyder.app import mainwindow
File "C:\Users\tiago\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 90, in
from qtpy import QtWebEngineWidgets # analysis:ignore
File "C:\Users\tiago\Anaconda3\lib\site-packages\qtpy\QtWebEngineWidgets.py", line 26, in
from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
ModuleNotFoundError: No module named 'PyQt5.QtWebKitWidgets'
The correct answer didn't work in my case.
This problem had to do with the PyQt5 installation. The way to fix it was to uninstall it
pip uninstall PyQt5
and then Spyder launched perfectly

Categories