How to have gst and gtk in python?

I need to run a Python program containing the following code:

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

Which packages should I specify to nix-shell?

You can use regular expression in this search page: NixOS Search - Loading...

for example, python.*gst and python.*gtk.

$ nix-shell -p 'python2.withPackages (p: with p; [pygtk gst-python])'

Unfortunately, that is not correct. At least for the GTK case. pygtk are abandoned bindings that only work on Python 2.

The modern gobject-introspection-based bindings (e.g. from gi.repository import Gtk) are usually provided by the regular library packages, so that would be gtk3 and gst_all_1.gstreamer. The package containing the magical gi module is python3.pkgs.pygobject3.

Some packages also use “pygobject overrides” to make the generated bindings more idiomatic. That is the case with GStreamer which has python3.pkgs.gst-python but not GTK.

The bindings are located at runtime with the help of GI_TYPELIB_PATH environment variable. In nixpkgs, we use gobject-introspection package setup hook to pick the bindings from buildInputs and set the env var and wrapGAppsHook to pass the environment variable to binaries. See the relevant section of the nixpkgs manual for more information.

Something like this

nix-shell -p gobject-introspection -p gtk3 -p gst_all_1.gstreamer -p 'python3.withPackages (p: with p; [pygobject3 gst-python])' --run python3

or better create a dedicated file

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  name = "gstreamer-with-gtk";

  nativeBuildInputs = [

  buildInputs = [
    (pkgs.python3.withPackages (p: with p; [
      pygobject3 gst-python