How to get a Python and GTK nix shell

I am trying to get a minimal example to work, in order to use python with GTK.

import gi
gi.require_version('Gtk', '3.0')

I get the following error.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/rwmfxzy7hi6vz8rj6wdv84h3vdk7jmfq-python3-3.11.6-env/lib/python3.11/site-packages/gi/", line 126, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace GTK not available

I have found this thread, which helped me understand some things.

I believe I once got the following shell.nix to work on 23.06, but in any case, on 23.11 it doesn’t work.

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
  buildInputs = with pkgs; [
    (python3.withPackages (p: with p; [

Am I missing something obvious? It doesn’t seem like it should be difficult to get working…

That sounds like you are importing GTK, rather than Gtk.