Libz.so.1 not found when running python script

Just installed python for the first time and trying to run WhisperNow but I’m getting the following error:

Reading inline script metadata from `transcribe.py`
Traceback (most recent call last):
  File "/home/guttermonk/Programs/WhisperNow/transcribe.py", line 12, in <module>
    from faster_whisper import WhisperModel
  File "/home/guttermonk/.cache/uv/archive-v0/QAcUD1QkqmSfndAU8wbNe/lib/python3.12/site-packages/faster_whisper/__init__.py", line 1, in <module>
    from faster_whisper.audio import decode_audio
  File "/home/guttermonk/.cache/uv/archive-v0/QAcUD1QkqmSfndAU8wbNe/lib/python3.12/site-packages/faster_whisper/audio.py", line 15, in <module>
    import av
  File "/home/guttermonk/.cache/uv/archive-v0/QAcUD1QkqmSfndAU8wbNe/lib/python3.12/site-packages/av/__init__.py", line 3, in <module>
    from av._core import time_base, library_versions, ffmpeg_version_info
ImportError: libz.so.1: cannot open shared object file: No such file or directory

I have zlib installed on my system, as well as the zlib python package. After doing some research on the issue, it looks like I perhaps need to specify the LD_LIBRARY_PATH? This thread also seems closely related, but the solution seems to be to export LD_LIBRARY_PATH to a temporary shell? After reading those threads, I’m still at a loss on how to do this correctly so that I can run the WhisperNow transcribe.py file from my toolbar.

this project require GitHub - SYSTRAN/faster-whisper: Faster Whisper transcription with CTranslate2.

This is available in nixpkgs, so you can try eg. nix-shell -p "python3.withPackages (p: [p.faster-whisper])"

Thanks for the help. Not sure if this is the same thing, but I have the following in my configuration.nix:

  environment.systemPackages = 
    (with pkgs; [
      (python312.withPackages(ps: with ps; [ faster-whisper sounddevice tkinter pandas requests zlib-ng ]))
    ]);

This will work.

I would prefer to keep my OS and my dev things separated, but this is up to you :slight_smile:

1 Like

I noticed that running printenv LD_LIBRARY_PATH returns:
/nix/store/2f53kw3hhb5an4iz3qzxz6xffxr20dc5-pipewire-1.2.7-jack/lib

And printenv | grep zlib doesn’t return anything. From what I’m gathering LD_LIBRARY_PATH should have the path to the libz library?

I tried adding an overlay per the wiki:

  nixpkgs.overlays = [
    (self: super: rec {
      pythonldlibpath = lib.makeLibraryPath (with super; [
        zlib zstd stdenv.cc.cc curl openssl attr libssh bzip2 libxml2 acl libsodium util-linux xz systemd
      ]);
      # here we are overriding python program to add LD_LIBRARY_PATH to it's env
      python312 = super.stdenv.mkDerivation {
        name = "python";
        buildInputs = [ super.makeWrapper ];
        src = super.python312;
        installPhase = ''
          mkdir -p $out/bin
          cp -r $src/* $out/
          wrapProgram $out/bin/python3 --set LD_LIBRARY_PATH ${pythonldlibpath}
          wrapProgram $out/bin/python3.12 --set LD_LIBRARY_PATH ${pythonldlibpath}
        '';
      };
    })
  ];

But I get the following error:

error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

       … while evaluating derivation 'nixos-rebuild'
         whose name attribute is located at /nix/store/hvs4if4zly4mp0fhbh86vh208x6fs8fg-source/pkgs/stdenv/generic/make-derivation.n

       … while evaluating attribute 'substitutions' of derivation 'nixos-rebuild'
         at /nix/store/hvs4if4zly4mp0fhbh86vh208x6fs8fg-source/pkgs/build-support/substitute/substitute.nix:56:5:
           55|   // lib.optionalAttrs (args ? substitutions) {
           56|     substitutions =
             |     ^
           57|       assert lib.assertMsg (lib.isList args.substitutions)

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: infinite recursion encountered
       at /nix/store/hvs4if4zly4mp0fhbh86vh208x6fs8fg-source/lib/strings.nix:2175:54:
         2174|     flag: feature: value:
         2175|     withFeature flag feature + optionalString flag "=${value}";
             |                                                      ^
         2176|

Admittedly completely new to python - any suggestions on what to do here, or if I’m on the right track even?

Figured out the solution! With the overlay, I just had to remove what I previously had in systemPackages and then add whatever you named the overlay derivation to systemPackages.