I get the following error:
Traceback (most recent call last):
File “/home/elzair/Development/python/./nixtest.py”, line 4, in
gi.require_version(‘Gtk’, ‘4.0’)
File “/nix/store/gwq3inwc86axcxb82jpwkzci3hjpw1xd-python3.10-pygobject-3.42.2/lib/python3.10/site-packages/gi/init.py”, line 126, in require_version
raise ValueError(‘Namespace %s not available’ % namespace)
ValueError: Namespace Gtk not available
What seems to be the problem? Am I just missing some dependencies?
In this simple case, you need gobject-introspection for its setup hook to set GI_TYPELIB_PATH variable. But for more complex examples, you will need other variables as well, and that is not possible to express in shebang easily – a variable extraction similar to Python + Qt woes - #2 by jtojnar will be required.
Traceback (most recent call last):
File "/home/mason/git/HexProver/hex_gui.py", line 4, in <module>
gi.require_version("Gtk", "3.0")
File "/nix/store/z2krx20irl3s8wrckq8r3fcyjvj1v51g-python3-3.10.12-env/lib/python3.10/site-packages/gi/__init__.py", line 126, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available
How are you creating the environment? Note that the supported method is using nix-shell, installing libraries globally through nix-env or NixOS configuration will not work, see FAQ - NixOS Wiki
Wow, okay, I figured out what was going on. I was using a different thing to make the the nix shell (i.e. not pkgs.mkShell) and it turns out there is a crucial difference between the two that I was not aware of. it works now
Looks like mkShell adds some extra environment variables that I was not aware of. This project is mostly pointless now that bash completion works in mkShell, but my flake generator uses it so I just use it by default. Gonna stop now though since I thought it behaved the same as mkShell (it does 99% of the time) and this bug was very hard to figure out.