Cyberithub

Solved "ModuleNotFoundError: No module named PyQt5"

Advertisements

In this article we will see how to solve "ModuleNotFoundError: No module named PyQt5" error. Last night when I was trying to build a python script on my system then I noticed "ModuleNotFoundError: No module named PyQt5" error on the output. So I decided to write a post about this while solving this error so that it will help you folks as well in case you are also facing the same error. But before that let's understand more about PyQt5 module.

PyQt5 is basically a comprehensive set of Python bindings for Qt v5. It is implemented as more than 35 extension modules and enables Python to be used as an alternative application development language to C++ on all supported platforms including iOS and Android. Check more about PyQtv5 on official website.

Solved "ModuleNotFoundError: No module named PyQt5"

Solved "ModuleNotFoundError: No module named PyQt5"

Also Read: Solved "No remote refs found similar to ‘flathub’" error

So when I was trying to build the setup.py script using python3 setup.py build command on my Ubuntu 20.04 LTS system, then I noticed below "ModuleNotFoundError: No module named PyQt5" error on the output.

NOTE:

Please note that here I am using root user to run all the below commands. You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.
root@cyberithub:~/Lector# python3 setup.py build
Traceback (most recent call last):
File "setup.py", line 4, in <module>
from lector.logger import VERSION
File "/root/Lector/lector/logger.py", line 22, in <module>
from PyQt5 import QtCore
ModuleNotFoundError: No module named 'PyQt5'

While the above error could occur due to any reason but most of the time it is basically due to missing PyQt5 python module. So to fix the error you need to install this module either through pip python package manager or through apt-get package manager. In our case we are using apt-get package manager to install the module. If you are using python3 then use apt-get install python3-pyqt5 command as shown below.

root@cyberithub:~/Lector# apt-get install python3-pyqt5
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libqt5designer5 libqt5help5 libqt5printsupport5 libqt5test5 python3-sip
Suggested packages:
python3-pyqt5-dbg
The following NEW packages will be installed:
libqt5designer5 libqt5help5 libqt5printsupport5 libqt5test5 python3-pyqt5 python3-sip
0 upgraded, 6 newly installed, 0 to remove and 183 not upgraded.
Need to get 5,642 kB of archives.
After this operation, 24.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
........................................

If you are using python2, then use apt-get install python-pyqt5 command as shown below.

root@cyberithub:~# apt-get install python-pyqt5

If you have have pip utility available in your system then you can also use pip install pyqt5 command to install this module.

root@cyberithub:~# pip install pyqt5

If you are using any MAC based system, then you can use brew package manager to install the module. You just need to run brew install pyqt command as shown below.

root@cyberithub:~# brew install pyqt

After installing the module if we now try to build the setup.py script again, then we can see this time it works as expected.

root@cyberithub:~/Lector# python3 setup.py build
/usr/lib/python3/dist-packages/setuptools/dist.py:481: UserWarning: The version specified ('0.5.GittyGittyBangBang') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.
warnings.warn(
running build
running build_py
creating build
creating build/lib
creating build/lib/lector
copying lector/settings.py -> build/lib/lector
copying lector/delegates.py -> build/lib/lector
copying lector/guifunctions.py -> build/lib/lector
copying lector/logger.py -> build/lib/lector
copying lector/annotations.py -> build/lib/lector
copying lector/metadatadialog.py -> build/lib/lector
copying lector/contentwidgets.py -> build/lib/lector
copying lector/__main__.py -> build/lib/lector
.............................

Hope this helps you fix "ModuleNotFoundError: No module named PyQt5" error on your System as well. Please let me know your feedback on comment box.

Leave a Comment