Wrap Python program to make them work in a virtualenv

Hi,

I’m currently using ranger with ueberzug for image preview. It works fine normally (shown as a home-manager package:

{ pkgs, ... }:

let
  rangerWrapped = pkgs.symlinkJoin {
    name = "ranger-bundle";
    paths = [ pkgs.ranger pkgs.ueberzug pkgs.python3.pkgs.pillow ];
    buildInputs = [ pkgs.makeWrapper ];
    postBuild = ''
      for prog in ranger rifle ueberzug; do
        wrapProgram $out/bin/$prog --prefix PYTHONPATH : $out/lib
      done
    '';
  };
in

{
  home.packages = [ rangerWrapped ];

  xdg.configFile."ranger/rc.conf".source = ./rc.conf;
}

But when I try to use it in an impure Python virtualenv:

        devShell = pkgs.mkShell rec {
          buildInputs = with pythonPackages; [
            # Dev tools
            virtualenvwrapper
            pylint
            # Pinned Python dependencies
            numpy
          ];

          shellHook = ''
            # Allow the use of wheels.
            SOURCE_DATE_EPOCH=$(date +%s)
            VENV=./.virtualenv

            if test ! -d $VENV; then
              virtualenv $VENV
            fi
            source $VENV/bin/activate

            # allow for the environment to pick up packages installed with virtualenv
            export PYTHONPATH=$VENV/${python.sitePackages}/:$PYTHONPATH

            # fix libstdc++.so not found error
            export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH
          '';
        };

ueberzug would complain about unable to import from PIL. I suspect this is because ueberzug is NOT sufficiently wrapped.

How can I fully wrap these programs so that they work in an impure Python virtualenv?

I was able to make it work by replacing --prefix PYTHONPATH : $out/lib with --set PYTHONPATH "out/lib"