How do I package an app with python dependencies?

Hello. I am trying to package GitHub - luisbocanegra/kde-material-you-colors: Automatic Material You Colors Generator from your wallpaper for the Plasma Desktop.

However, the app depends on numpy and dbus-python. Just adding them to buildInputs doesnt work, and the program does not see them.

I tried using buildPythonApplication with format = "other" and doCheck = false, but it does not wrap the binary for some reason.

How can I package it?

My current derivation:

{ stdenv
, fetchFromGitHub
, python3
, python3Packages
, lib

stdenv.mkDerivation rec {
  pname = "kde-material-you-colors";
  version = "0.5.0BETA";

  src = fetchFromGitHub {
    owner = "luisbocanegra";
    repo = "kde-material-you-colors";
    rev = "v${version}";
    sha256 = "1507i5h0wi5s8sx0l0qgi42cas40lh4g8dzg6rw9v2znzcm26bvb";

  buildInputs = [ python3 python3Packages.dbus-python python3Packages.numpy ];

  postPatch = ''
    substituteInPlace kde-material-you-colors \
      --replace /usr/bin/python3 python3

    substituteInPlace kde-material-you-colors \
      --replace /usr/lib $out/lib

    substituteInPlace kde-material-you-colors.desktop \
      --replace /usr/bin/kde-material-you-colors kde-material-you-colors

    substituteInPlace \
      --replace /usr $out

  installPhase = ''
    mkdir -p $out/lib/${pname}
    mkdir $out/bin
    cp -f *.{py,conf,desktop} $out/lib/${pname}/
    cp -f kde-material-you-colors $out/bin/kde-material-you-colors
    cp -f material-color-utility-bin $out/lib/${pname}/material-color-utility-bin
    cp -f $out/lib/${pname}/

    chmod 755 $out/lib/${pname}/*.py
    chmod 664 $out/lib/${pname}/*.{desktop,conf}
    chmod 755 $out/bin/kde-material-you-colors
    chmod 755 $out/lib/${pname}/material-color-utility-bin
    chmod 755 $out/lib/${pname}/

    ln -sf $out/lib/${pname}/material-color-utility-bin $out/bin/material-color-utility

  meta = with lib; {
    description = "Automatic Material You Colors Generator from your wallpaper for the Plasma Desktop";
    downloadPage = "";
    changelog = "${version}";
    license = licenses.asl20;
    maintainers = with maintainers; [ flexagoon ];

Python is only aware of modules if it’s passed on PYTHONPATH, or part of the executables site-packages.

You probably want to use pythonX.withPackages, which will create an interpreter + modules in a single derivation.

Thanks, this worked!