PyGObject: `GtkWindow' doesn't support property `title'

I’m using PyGObject to create a Window.
The examples I’ve found say to use Gtk.Window(title='Hello World'), but I get the error:

TypeError: gobject 'GtkWindow' doesn't support property 'title'

Removing the title part from the args just causes other errors.

TypeError: <Gtk.Window object at 0x7fd17845c8c0 (GtkWindow at 0x201c280)>: unknown signal name: destroy

It seems something is not quite right.

test.py

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

window = Gtk.Window(title="Hello World")
window.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()

shell.nix

{ pkgs ? import <nixpkgs> {} }:

let
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "3.3.0";
  }) {};
  custom-python = mach-nix.mkPython {
    python = "python38";
    requirements = ''
      PyGObject
    '';
    providers = {
      _default = "nixpkgs,wheel,sdist";
      PyGObject3 = "nixpkgs";
    };
  };
in pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    gobject-introspection
  ];
  buildInputs = with pkgs; [
    gtk3
    custom-python
  ];
}

Full error:

$ python test.py 
Traceback (most recent call last):
  File "test_pygobject.py", line 5, in <module>
    window = Gtk.Window(title="Hello World")
  File "/nix/store/nhs0qlhzdcwd7ssiajrmd36x7wcahm02-python3-3.8.9-env/lib/python3.8/site-packages/gi/overrides/Gtk.py", line 522, in __init__
    _window_init(self, *args, **kwargs)
  File "/nix/store/nhs0qlhzdcwd7ssiajrmd36x7wcahm02-python3-3.8.9-env/lib/python3.8/site-packages/gi/overrides/__init__.py", line 319, in new_init
    return super_init_func(self, **new_kwargs)
TypeError: gobject `GtkWindow' doesn't support property `title'

Try to add gtk3, glib and gsettings-desktop-schemas to buildInputs and wrapGAppsHook to nativeBuildInputs.

Still getting the same errors =/

I’m not sure why, but there seems to be something in mach-nix causing this.
When I remove mach-nix from the equation, it works.

shell.nix

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    gobject-introspection
  ];
  buildInputs = with pkgs; [
    (python38.withPackages (ps: with ps; [
      pygobject3
    ]))
    glib
    gtk3
    pkgconfig
    bashInteractive
  ];
}

for nix there are some basic rules

  • don’t mix channels
  • take special attention to anything that is UI related

if you take the the channel from mach-nix instead of <nixpkgs> it should be fine

let
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "3.3.0";
  }) {};

  pkgs =  mach-nix.nixpkgs ; 

  custom-python = mach-nix.mkPython {
    #python = "python38Full";
    python = "python38";
    requirements = ''
      PyGObject
    '';
    providers = {
      _default = "nixpkgs,wheel,sdist";
      PyGObject3 = "nixpkgs";
    };
  };
in pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    gobject-introspection
  ];
  buildInputs = with pkgs; [
    custom-python
    gtk3
  ];
}

I would prefer:

let
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "3.3.0";
  }) {};
  pkgs =  mach-nix.nixpkgs ; 

  custom-python = mach-nix.mkPython {
    python = "python38";
    requirements = ''
      PyGObject
    '';
    
  };
in pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    gobject-introspection
  ];

  buildInputs = with pkgs; [
    custom-python
    gtk3
  ];
}

I personally recommend to python “always” on the first buildInputs position


If you go for UI / tkinter use can start with Python3.xFull

Thanks for your great reply. It’s really hard to find a single source of truth for all these little bits of minutia.

Confirmed that your shell.nix works, and also works for my extended use case with PyWebview.
It’s a lot more verbose than my minimal version, but it lets me get access to PyPi which is always a big plus!

let
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "3.3.0";
  }) {};
  pkgs =  mach-nix.nixpkgs ;
  cottonmouth = mach-nix.buildPythonPackage {
    name = "cottonmouth";
    src = builtins.fetchGit {
      url = "https://github.com/adamlwgriffiths/cottonmouth";
      ref = "master";
      rev = "34b20827200b41208b2e5a90b4d9c713a74e4939";
    };
  };
  custom-python = mach-nix.mkPython {
    python = "python38";
    requirements = ''
      PyGObject
      pywebview
    '';
    packagesExtra = [
      cottonmouth
    ];
    providers = {
      PyGObject3 = "nixpkgs";
      pywebview = "nixpkgs";
    };
  };
in pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    gobject-introspection
  ];

  buildInputs = with pkgs; [
    custom-python
    gtk3
    webkitgtk
  ];
}

please check your logs

  • pygobject - 3.40.1 - sdist
  • pywebview - 3.4 - wheel

None of them is nixpkgs, like you wanted to configure?
There is case sensitivity/naming matters.


(explizit) pin for pypi:

let
  pypiDataRev="7f28322aa7baec80e261002076e7b322f153e12f" ;  pypiDataSha256="1dj7dg4j0qn9a47aw9fqq4wy9as9f86xbms90mpyyqs0i8g1awjz" ;  ## commit: master # 2021-08-29T07:53:42Z # DavHau/pypi-deps-db

  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "3.3.0";
  }) {
    inherit pypiDataRev pypiDataSha256 ;
  };

Great feedback, and it touches on another point I’m not sure of, specifically:

How mach-nix handles mismatching names
Ie:
pypi = “PyGObject”
nixpkgs = “pygobject3”

What is the proper way of specifying this in requirements and mach-nix.providers and having mach-nix understand the association?

When I change providers._default = "nixpkgs"; it prints out pygobject. So it seems you just, lower case the requirements.txt file?

Specifically
providers.pygobject3 doesnt work
providers.PyGObject doesnt work
providers.pygobject does work

Looks like this is broken again after having updates to 21.11.
Again, using packages from mach-nix results in TypeError: gobject 'GtkWindow' doesn't support property 'title'.
Using PyGObject from nixpkgs without mach-nix works.

Output from nix-shell indicates that nixpkgs are being used:

building '/nix/store/gkfyjvmkjk040zhmimp78fbs73yswrcz-mach_nix_file.drv'...

### Resolved Dependencies ###

pygobject - 3.42.0 - nixpkgs (attrs: pygobject3)
└── pycairo - 1.20.1 - nixpkgs (attrs: pycairo)

Total number of python modules: 2
Removed circular dependencies: 0

shell.nix

let
  # https://github.com/DavHau/pypi-deps-db
  # commit: 75b342a905d519683079e4f98aa2b8d05628b68f
  # Thu Mar 10 20:35:51 UTC 2022
  pypiDataRev="75b342a905d519683079e4f98aa2b8d05628b68f";
  pypiDataSha256="14mjsyybw4bmrn35970hdq9ikw1951hqwvbbv24ij3csdrvbcvhb";
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix";
    ref = "3.4.0";
  }) {
    inherit pypiDataRev pypiDataSha256;
  };
  pkgs =  mach-nix.nixpkgs;

  custom-python = mach-nix.mkPython {
    python = "python39";
    requirements = ''
      PyGObject>=3.42.0
    '';
    providers = {
      _default = "nixpkgs,wheel,sdist";
    };
  };
in pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    gobject-introspection
  ];

  buildInputs = with pkgs; [
    custom-python
    glib
    gtk3
  ];
}