A
A
agent_22032021-05-11 15:11:06
PyQt
agent_2203, 2021-05-11 15:11:06

How to fix import error in PyQT5 library?

I have a code where the following functions are imported from PyQT5:

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKit import *
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtWebEngine import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtNetwork import *
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication


Everything works fine on my PC, here are the versions of the libraries with pip:

PyQt5==5.15.2
PyQt5-sip==12.8.1
PyQtWebEngine==5.15.2


However, when I run the same script on the server (Ubuntu 20.04), the following error occurs:

Traceback (most recent call last):
  File "headless_browser.py", line 6, in <module>
    from PyQt5.QtWebKit import *
ModuleNotFoundError: No module named 'PyQt5.QtWebKit'


Here are all the library dependencies on the server on the server with pip3:

PyQt5==5.15.2
PyQt5-Qt5==5.15.2
PyQt5-sip==12.8.1
PyQtWebEngine==5.15.2
PyQtWebEngine-Qt5==5.15.2


Can you suggest where to dig? I have never come across PyQT5, only worked on selenium. I re-read many articles, but everywhere it says only that qt was removed in version 5.6, but on the server and on my PC it is 5.15.2.
Could this be related to one of the fact that I have Arch Manjaro Linux on PC and Python 3.9, but 3.8 on the server?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
agent_2203, 2021-05-13
@agent_2203

It is strange that this is practically not written anywhere, but I found the following solution:

apt-get install python3-pyqt5.qtwebengine
apt-get install python3-pyqt5.qtwebkit

Further, if you are using headless, then we indicate, otherwise PyQT will throw an error:
export QT_QPA_PLATFORM=offscreen

A
Alan Gibizov, 2021-05-12
@phaggi

agent_2203 , what was your goal when you wrote this code? So that your program, copied to ubuntu, will take these libraries from somewhere and run? So after all, they need to be installed there, on ubuntu.
Or build a project on your computer that includes everything you need for it (there are many different programs, such as cx_Freeze, py2exe, nuitka, PyInstaller, etc., that do this). This is a non-trivial task, since most of the popular project builders have control stuck at the 1987 ini level...well, there it is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question