ModuleNotFoundError: No module named 'PyQt5'/'PyQt6'

I have a log-in tkinter file that invokes a pyqt class after succesfully logging in. However, even after I logged, the pyqt file window doesn’t show up and instead gives me an error that the module isn’t found even though I already have it installed (note: I’m using Python 3.10.9) I used both PyQt5 and PyQt6 and no luck for either. Is there something that I’m missing? What’s weird is that when I run the pyqt file, it actually shows the window. It’s only when I try to call it from the tkinter file that it for some reason doesn’t want to work.

I asusme you used pip or your OS package manager to install PyQt5 or PyQt6 so it should be able to be imported.

Share the full error message you see and the code that raises the error please.

Yes I did use pip to install them (python -m pip install PyQt).

As for the error:

Traceback (most recent call last):
  File "C:\Users\UserPC\OneDrive\Documents\ProjectSICI\", line 8, in <module>
    import PyQt6
ModuleNotFoundError: No module named 'PyQt6'

Exactly what steps did you take to install it?

How do you know the program is using Python 3.10.9? What steps do you take to verify this?

In total, how many installations of Python do you believe are on the computer, including virtual environments? How did you come to this conclusion?

Exactly what steps do you take, in order to “run the pyqt file”? (does that mean Python source code, or something else?) What is this file - where is it named, and what does it contain? Same questions for “the tkinter file”.

I’m newer to Python. You didn’t mention your OS, so on Windows your path could be the issue here.

On Windows I had to change my path in my CLI (cmd.exe) to point to 3 different Python directories.


Also I use a virtual environment. You will need to learn about this. But if you’re doing a tutorial, like from Udemy, it can be confusing as some longer tutorials use various version of Python as they update the tutorial over time.

Virtual environment basics.

  1. Install the virtual env with py -m pip install virtualenv
  2. Make a project folder, let’s call this “proj1”.
  3. Using your CLI go into folder “proj1”.
  4. Init the virtual env in your “proj1” with virtualenv .venv. This creates a folder in your proj1 dir called “.venv”.
  5. Activate your virtual env by typing .venv\scripts\activate. There are scripts for every OS under .venv\scripts\.
  6. Install your other modules like PyQt.
  7. Begin programming in this “proj1” project.
  8. When done programming or switching to another program folder, deactivate your environment with .venv\scripts\deactivate.

Someone correct me if I’m wrong but each of your projects will have it’s own modules installed.

Its not called PyQt it is called PyQt6 what did you install?
You can confirm what is installed with python -m pip list.
Then check that it is installed correctly like this python -c "import PyQt6"

I had to change the name of Python 3.12’s interpreter as no matter what I select, it always set Python 3.12 as my default. I also added the Python versions on the enviromental variables’ paths.

Just in case, I also tried Python 3.11.9 (though unfortunately PySide2 doesn’t support it) but now it gives me an error that the QT-PyQt-PySide-Custom-Widgets doesn’t have a cairo library:

Traceback (most recent call last):
  File "C:\Users\UserPC\OneDrive\Documentos\ProjectSICI\", line 12, in <module>
    from Custom_Widgets.Widgets import *
  File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\Custom_Widgets\", line 12, in <module>
    from Custom_Widgets.Qss.SvgToPngIcons import NewIconsGenerator
  File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\Custom_Widgets\Qss\", line 22, in <module>
    import cairosvg
  File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairosvg\", line 26, in <module>
    from . import surface  # noqa isort:skip
  File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairosvg\", line 9, in <module>
    import cairocffi as cairo
  File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairocffi\", line 47, in <module>
    cairo = dlopen(
  File "C:\Users\UserPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\cairocffi\", line 44, in dlopen
    raise OSError(error_message)  # pragma: no cover
OSError: no library called "cairo-2" was found
no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library '': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called ''
cannot load library 'libcairo.2.dylib': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.2.dylib'    
cannot load library 'libcairo-2.dll': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo-2.dll'        

Here’s the script of the file:

import os
import sys

import csv
from propiedades1 import *

# from PyQt5 import QtCore, QtGui, QtWidgets
# from PyQt5.QtWidgets import QApplication, QMainWindow
# from PyQt5.QtGui import *
# from PyQt5.QtCore import *
from Custom_Widgets.Widgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *
import PySide6.QtWidgets
from functools import partial

shadow_elements = { "left_menu","frame_3", "frame_5", "header", "frame_8"}

class MainWindow(QMainWindow):
        def __init__(self,parent=None):
            self.ui = Ui_MainWindow()
            loadJsonStyle(self, self.ui)
            for x in shadow_elements:
                effect = QtWidgets.QGraphicsDropShadowEffect(self)
if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    window = QMainWindow()

You are on a Windows machine, right? And you want to use a Qt library. Quick question: have you installed Qt on your system? And I’m not speaking about PyQt but a system’s library.

I don’t think I have, it seems. Where can I install one and should I add it through my pc’s enviromental variables?

Quick googling shows me this:

Oops, sorry, I gave you old link. Try this:

(It is of version 5.12.12 unfortunately, so you have to have got also PyQt5)

The PyQt PyPI packages include all the require Qt DLLs and data files.
There is no need install any Qt development kits.

I assume that you tried PySide becuase you cannot get PyQt5/PyQt6 working?
What ever you are doing wrong will not be fixed by using PySide.

1 Like

Please see: