Running PyQt5 app: ModuleNotFoundError: No module named 'PyQt5'

after building stargate: init at 21.11.5 by yuuyins · Pull Request #145153 · NixOS/nixpkgs · GitHub, and trying to run the binary i get

$ ./result/usr/bin/stargate
Adding PYTHONPATH /nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr
Did not detect local development environment, trying system installation
Adding PYTHONPATH /nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/share/stargate/stargate
[2021-11-14 18:12:12,753] INFO /nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/bin/.stargate-wrapped: 72 - sys.argv == ['/nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/bin/.stargate-wrapped']
[2021-11-14 18:12:12,756] ERROR /nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/share/stargate/stargate/sglib/log.py: 90 - Traceback (most recent call last):

  File "/nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/share/stargate/stargate/sgui/sgqt.py", line 7, in <module>
    import PyQt6

ModuleNotFoundError: No module named 'PyQt6'


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/bin/.stargate-wrapped", line 170, in <module>
    main()

  File "/nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/bin/.stargate-wrapped", line 167, in main
    start_stargate()

  File "/nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/bin/.stargate-wrapped", line 95, in start_stargate
    app, scaler = _setup()

  File "/nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/bin/.stargate-wrapped", line 73, in _setup
    from sgui.sgqt import QApplication, QGuiApplication, QtCore

  File "/nix/store/l4kmk3654h6vyg4k3ayr86kc2avrqccb-stargate-21.11.5/usr/share/stargate/stargate/sgui/sgqt.py", line 11, in <module>
    import PyQt5

ModuleNotFoundError: No module named 'PyQt5'

even though i have wrapped the binary with qt. I am at a loss how to fix this. Any idea?

about that PYTHONPATH thing the developer said

Technically it’s messing with sys.path and not PYTHONPATH, which are kind of related but not the same thing. I’ll change the log message.
But to be extra clear, it adds things to sys.path to find it’s own installation, not to import system dependencies like PyQt. Only internal dependencies like sgui, sglib and sg_py_vendor

the only related issue i could find is Carla window is black when loaded as a plugin · Issue #67923 · NixOS/nixpkgs · GitHub

2 Likes

PyQt5/6 on nixos is always a hassle in my experience… Maybe it helps if you install PyQt from the nix-store and do the rest in a .venv like it did here. Although not sure if this works in your situation…