ModuleNotFoundError 'PyQt6' -- frustration

Question:
I am trying to learn pyqt using replit.com. I don’t know how to troubleshoot the error that I get. What do I need to do to be able to use pyqt in replit?

These are the steps I took.
I created a new repl, pasted in code from pythonguis.com, clicked run. Repl does its thing. The end result is an error.

This is the error that I get when I try to run pyqt:

 python3 main.py
Traceback (most recent call last):
  File "/home/runner/CumbersomeSoreOrder/main.py", line 1, in <module>
    from PyQt6.QtWidgets import QApplication, QWidget
ModuleNotFoundError: No module named 'PyQt6'
exit status 1
from PyQt6.QtWidgets import QApplication, QWidget
import sys
app = QApplication(sys.argv)
window = QWidget()
window.show()
app.exec()

Have you imported the PyQt6 module? If not, type this command into the Shell: pip install PyQt6 or this one: poetry and PyQt6.

After I pip install PyQt6, I got this error when running it:
Got this error:

 python3 main.py
Traceback (most recent call last):
File “/home/runner/CumbersomeSoreOrder/main.py”, line 1, in
from PyQt6.QtWidgets import QApplication, QWidget
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
exit status 1

try in the shell
nix-env -A nigpkgs.libgl
Or nixpkgs.opengl

Got these errors:

~/CumbersomeSoreOrder$ nix-env -A nigpkgs.libgl
error: no operation specified
Try 'nix-env --help' for more information.

~/CumbersomeSoreOrder$ nixpkgs.opengl
bash: nixpkgs.opengl: command not found

Instead of trying to install this package, you should create a new repl using the pygame template instead of the python template. This is because pygame repls have (graphical) output configured while python repls don’t. (I’m not entirely sure that PyQt6 will work in a pygame repl, but it definitely won’t in a python repl.)

When you create your pygame repl, copy your code in and then install PyQt6 with poetry add PyQt6

Follow your suggestion. I got same error when running it:

 python3 main.py
Traceback (most recent call last):
  File "/home/runner/UpbeatAdventurousTranslations/main.py", line 3, in <module>
    from PyQt6.QtWidgets import QApplication, QWidget
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
exit status 1

I see, try this:
Show hidden files (click three dots), then open the replit.nix file. In the deps list, add pkgs.libGL
The file should now look like this:

{ pkgs }: {
	deps = [
		pkgs.libGL
	];
}

Then see if PyQt6 works.

still got the same import error:

 python3 main.py
Traceback (most recent call last):
  File "/home/runner/UpbeatAdventurousTranslations/main.py", line 3, in <module>
    from PyQt6.QtWidgets import QApplication, QWidget
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
exit status 1

Have you refreshed the tab?

I did that twice. Got out of the repl and got back in. Ran it. same error. Very frustrating.

Okay, I am going to try to get it to work. I’ll update you once I do it.

looking forward to it.

Fork the PyQt6 template I have created.

A bonus of the template is that it uses very little storage even though the library itself is extremely large. You should delete the repls of yours that have PyQt6 installed, because installing it directly takes up so much storage.

The fix was actually much simpler than I expected.

1 Like

Hi @NuclearPasta0 !
What fix did you use? Can you post it directly?

1 Like

Fix:
Open hidden file replit.nix, and then add python310Packages.PyQt6 to the deps list. The python version can be 11 instead of 10, and the PyQt version can be 5 or 4 instead of 6.
Note that the module still might not be found because PyQt6 might not be in sys.path. I think I experienced this on the python template and not on the pygame template.

1 Like

I knew it would be something with Nix, great job figuring it out! :rocket:

Yeah! It worked. You’re my hero/heroine!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.