Python 3.10 - ImportError for PyQt5 - python

I have built a program that edit excel sheets. I build a GUI with PyQt5 for it. I used Qt Creator to generate the code for the GUI. The program was working fine before, but after I tried to make it into an app with py2app and pyinstaller I keep getting an Import Error:
(venv) Febins-MacBook-Pro:Planner Builder Febin.J$ "/Users/Febin.J/Documents/Projects/Python Projects/Planner Builder/venv/bin/python" "/Users/Febin.J/Documents/Projects/Python Projects/Planner Builder/birthdaywindow.py"
Traceback (most recent call last):
File "/Users/Febin.J/Documents/Projects/Python Projects/Planner Builder/birthdaywindow.py", line 11, in <module>
from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: cannot import name 'QtCore' from 'PyQt5' (/Users/Febin.J/Documents/Projects/Python Projects/Planner Builder/venv/lib/python3.10/site-packages/PyQt5/__init__.py)
The strange this is that it was working fine before. This is my packages installed:
altgraph==0.17.2
appscript==1.1.2
auto-py-to-exe==2.14.0
beautifulsoup4==4.10.0
bottle==0.12.19
bottle-websocket==0.2.9
bs4==0.0.1
certifi==2021.10.8
charset-normalizer==2.0.9
Eel==0.12.4
et-xmlfile==1.1.0
future==0.18.2
gevent==21.12.0
gevent-websocket==0.10.1
greenlet==1.1.2
idna==3.3
macholib==1.15.2
modulegraph==0.19.2
numpy==1.22.0
openpyxl==3.0.9
Pillow==8.4.0
psutil==5.9.0
py2app==0.26.1
pyinstaller==4.7
pyinstaller-hooks-contrib==2021.5
PyQt5==5.15.6
PyQt5-Qt5==5.15.2
PyQt5-sip==12.9.0
requests==2.26.0
soupsieve==2.3.1
urllib3==1.26.7
whichcraft==0.6.1
xlwings==0.25.3
zope.event==4.5.0
zope.interface==5.4.0
This is where the error occurs:
1 # -*- coding: utf-8 -*-
2
3 # Form implementation generated from reading ui file 'mainwindow.ui'
4 #
5 # Created by: PyQt5 UI code generator 5.15.6
6 #
7 # WARNING: Any manual changes made to this file will be lost when pyuic5 is
8 # run again. Do not edit this file unless you know what you are doing.
9
10
11 from PyQt5 import QtCore, QtGui, QtWidgets
12 import datetime
13 from datetime import *
14 from eventwindow import Ui_EventWindow
15 from webScraping import publicHolidays, schoolHolidays, uniHolidays
16 from main import creating_planner
Could you please help me solve this error?

I think there isn't support yet for Python 3.10:
https://github.com/altendky/pyqt-tools/issues/98

I had the same issue. I was finally able to install PyQt5 by forcing the version to 5.15.5 that is supported by Python 3.10. You can use the below command line:
pip install PyQt5==5.15.5

Related

Can't import PyQt5.QtWebEngineWidgets

I'm trying to make an vocabtrainer for myself to get better in english, cause I suck. To achieve this, I'm trying to make a GUI with PyQt5 to expand my programming experience too :). But somehow I can't import the QtWebEngineWidget...
This is my code:
import PyQt5.QtWidgets as pyqtW
import PyQt5.QtGui as pyqtG
import PyQt5.QtCore as pyqtC
from PyQt5.QtWebEngineWidgets import *
import sys
class VocabTrainer:
def __init__(self):
self.main = pyqtW.QApplication([])
self.window = pyqtW.QWidget()
self.prepareWindow()
sys.exit(self.main.exec_())
def prepareWindow(self):
"""
Set's the attributes of the window.
"""
# window settings
self.window.resize(250, 100)
self.window.show()
def openPons(self):
"""
Opens the website of pons to be able to translate words.
"""
pass
test = VocabTrainer()
My IDE (PyCharm) warns me that it can't find the reference of PyQt5.QtWebEngineWidgets and if I run this code, I'll get this error message:
Traceback (most recent call last):
File "/A/little/path/VocabTrainer.py", line 12, in <module>
from PyQt5.QtWebEngineWidgets import *
ImportError: libQt5Quick.so.5: cannot open shared object file: No such file or directory
Process finished with exit code 1
I've installed the modules with the following commands:
pip install pyqt5
pip install pyqtwebengine
I've also tried to reinstall the modules but without success.
Python-Version: 3.8.1
OS: Arch Linux
In the case of ArchLinux, having the most up-to-date packages, I generally recommend using the repository packages (IMHO Arch Linux is a good laboratory to test the new functionalities :-)). Considering the above, I recommend installing pyq5 and pyqtwebengine by running the following:
sudo pacman -S python-pyqt5 python-pyqtwebengine
You must also change the python that pycharm uses to the system.

PyQt5 Error in PyCharm IDE

I have PyQt5 Installed and I created a GUI and edited it using Sublime Text, Now I want to use PyCharm and I saw posts that you don't have to configure PyQt5, it is automatically detected by PyCharm.
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPixmap
from mainpy import kitcode
PyQt5, QtCore, QtGui, QtWidgets, PyQt5.QtWidgets, PyQt5.QtGui, QPixmap, mainpy and kitcode are all in red underline.
And when I run it, I get the error
Traceback (most recent call last):
File "C:/Users/username/Desktop/folder/PythonThesis/mainpy.py", line 9, in <module>
from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: No module named 'PyQt5'
Process finished with exit code 1
any help would be appreciated and sorry if this is basic, I am still new to python. Thank you very much.
did you fix this problem?
You may need to tell PyCharm which Python do you want to use for your current project. You can do this by configuring Python interpreter from Settings/Preferences/Project Interpreter. Be careful to find the proper Python with PyQt5. You can find more information on the official website. An extra tip is you can edit run configuration, including Python interpreter for the next run, before running projects by using the shortcut Shift+Alt+F10.

Python 2.7.11 - ImportError: cannot import name QtWebKit - Kali Linux / Debian 8

I'm trying to launch an app dependant on QtWebKit but i'm unable to import the module. I've tried debugging by launching python and importing other modules. They all work fine (e.g. from PyQt4 import QtGui, QtCore) works without any issues, but when i run
from PyQt4 import QtGui, QtCore, QtWebKit
I receive the following:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name QtWebKit
I have also tried the following to no avail (they install fine but do not fix the issue):
apt-get install --reinstall python-qt4
apt-get install --reinstall python-2.7
This is an issue with the app, sparta?.
Debian Stretch which Kali Rolling is based on has mothballed QtWebKit in PyQt4.
The latest version does not contain QtWebkit.so.
Unfortunately the code in question needs to be updated to use an alternative such as PyQt5 equivalent module.
A bug report concerning this can be found on the kali bug report site from Jun/2/2016
optional bodge/quick n dirty fix [works in latest build of Kali]
In the mean time and if it is sparta and you need it functional now:
apt-get install python-pyside.qtwebkit
clone a copy from https://github.com/SECFORCE/sparta to where ever suits, in my case /opt/recon/sparta, this preserves the system version so it can fixed updated normally.
edit sparta.py
remove QtWebKit from line 22
insert the code from line 26 to 30
21 try:
22 from PyQt4 import QtGui, QtCore
23 except:
24 print "[-] Import failed. PyQt4 library not found. \nTry installing it with: apt-get install python-qt4"
25 exit()
26 try:
27 from PySide import QtWebKit
28 except:
29 print "[-] Import failed. QtWebkit library not found. \nTry installing it with: apt-get install python-pyside.qtwebkit"
30 exit()
edit ui/view.py
comment out line 15
15 #from PyQt4 import QtWebKit # to show html code (help menu)
16 from PySide import QtWebKit # to show html code (help menu)
edit line 54 the original can be seen below
54 self.helpWidget.load(QUrl('./doc/help.html'))
This should be modified to
54 self.helpWidget.load('./doc/help.html')
Disclaimer This is a 5 minute fix, look to the project homepage for longterm fix.
On latest version sparta and Kali:
Linux kali 4.14.0-kali1-amd64 #1 SMP Debian 4.14.2-1kali1 (2017-12-04) x86_64 GNU/Linux
You need modify:
Comment :
16 #from PyQt4 import QtWebKit
Add:
17 from PySide import QtWebKit
Modify:
54 self.helpWidget.load('./doc/help.html')
Unfortunately developers have no time and resources to fix the issue permanently. But you can get updated and compatible with Kali version here
https://github.com/alexxn/sparta
install python3-pyqt5.qtwebkit
the solution is here:
https://github.com/sourcepole/qgis-openlayers-plugin/issues/56#issuecomment-387223048
worked for me

PyQt4 x64 is not importing from network location

I want to use PyQt4 from a network location.
I installed Python 2.6.4 x32 in a client and kept PyQt4 x32 module in a network share (for Ex: "\share\Pyton_Modules\x32").
when opened python i did as below and it worked
import sys
sys.path.append(r'\\share\Pyton_Modules\x32')
from PyQt4 import QtGui
everything worked fine.
But i tested the same way for python 2.6.4 x64 in a client and keeping PyQt4 x64 in a network share (for Ex : "\share\Pyton_Modules\x64")
when opened python i did as below and it didn't worked
import sys
sys.path.append(r'\\share\Pyton_Modules\x64')
from PyQt4 import QtGui
i get below error
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
from PyQt4 import QtGui
ImportError: DLL load failed: The specified module could not be found.
I found a solution to overcome my situation.
I moved all the files from PyQt4\bin to PyQt4 and it worked without any issue...
Hope this could help someone.

Python: from import error

I'm running Python 2.6.6 on Ubuntu 10.10.
I understand that we can import a module and bind that module to a different name, e.g.
import spam as eggs
also,
from eggs import spam as foo
My problem is that when running the PySide examples, the following import code does not run:
import PySide as PyQt4
from PyQt4 import QtCore, QtGui
It generates an import error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PyQt4
Clearly, according to the Python interpreter the above code is incorrect, my question is why is it incorrect or rather why doesn't this work?
import and from are a special syntax.
They look for a module name, which means a file in sys.path which starts with the module name.
And it seems like you don't have PyQt4 installed, so it will fail.
The fact that you have a variable called PyQt4 in your namespace after running import PySide as PyQt4 does not change anything, Python is still looking for an actual module called PyQt4 when you do from PyQt4 import QtCore, QtGui.
Try doing
import PySide as PyQt4
QtCore = PyQt4.QtCore
QtGui = PyQt4.QtGui
or
import PySide as PyQt4
from PySide import QtCore, QtGui
That should be equivalent.
I just installed PySide and was doing a tutorial where all the examples used PyQt4. I got tired of changing the imports from PyQt4 to PySide so I just made a symlink in my site-packages, using the following steps:
1) There's surely a better way but I found where my python packages were installed by opening a shell and running python, then at the interactive interpreter typed:
>>> import sys
>>> print sys.path
2) I then found PySide in one of the directories and cd'd to it (n.b. It's at /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages if you're using the macports PySide install for python 2.7 on Mac OSX Leopard 10.5.8).
3) Then I made a symlink with ln, in my case I had to use sudo:
sudo ln -s PySide PyQt4
That's it, now I can just use:
from PyQt4 import QtGui
as normal - happy days!
Obviously, if you ever want to install PyQt4 you should rm the PyQt4 symlink first.
Another caveat: What I've described above may well be wrong/bad in many ways - I am no expert at Python installs but so far it's ok for me. YMMV so use at your own risk. Hopefully someone will comment soon to say "no, very bad!" or ideally "yeah don't sweat it, we cool.."

Categories

Resources