pythongtk3nixos

Wanting to use Gtk3 with Python3 on NixOS


I want to use Gtk3 in Python3 on NixOS. This command

nix-shell -p gobject-introspection gtk3 'python3.withPackages(ps : with ps; [ pygobject3 ])'

allows import gi in the python3 environment within the nix-shell. This is how I am trying to define Gtk for Python3 in the configuration.nix file.

  environment.systemPackages = with pkgs; [
    gtk3
    python3
    python3Packages.pygobject3
    python3Packages.pip
  ];

The sudo nixos-rebuild switch command does not show any error, but import gi within the python3 environment results in:

ModuleNotFoundError: No module named 'gi'

What do I need to change?

This is a fresh install of NixOs with the Cinnamon DE, Python 3.11.8, Gtk 3.24.


Solution

  • This is how I modified my configuration.nix file, thanks to the comment of @CharlesDuffy.

      users.users.reb = {
        isNormalUser = true;
        description = "RB";
        extraGroups = [ "networkmanager" "wheel" ];
        packages = with pkgs; [
          firefox
          libreoffice-fresh
          vlc
          gtk3
          (python3.withPackages (subpkgs: with subpkgs; [
            pip
            pygobject3
          ]))
        #  thunderbird
        ];
      };