Best way to find necessary system libraries for Python projects

Some years later, I have the same problems and the same question as you… It seems there is no other way than adding more and more stuff to your nix-shell until it works. In my case it was y ImportError: libexpat.so.1: cannot open shared object file error, followed by the same ImportError: libz.so.1 error and so i found this post. I just want to share my FHSUserEnv which should work for a lot of python packages:

{ pkgs ? import <nixpkgs> {} }:
# https://ryantm.github.io/nixpkgs/builders/special/fhs-environments/
(pkgs.buildFHSUserEnv {
  name = "choose your own"; # <-- set name here
  # Packages to be installed for the main host's architecture (i.e. x86_64). Along with libraries binaries are also installed.
  targetPkgs = pkgs: (with pkgs; [
    # *** Python***
    python311Full
    python311Packages.pip
    # *** OS ***
    libgcc 
    binutils
    coreutils
    expat
    libz
  ]);
 # Packages to be installed for all architectures supported by a host (i.e. i686 and x86_64). Only libraries are installed by default.
  multiPkgs = pkgs: (with pkgs; []);
  runScript = "bash";
}).env

Furthermore, sometimes you have to set LIBRARY_PATH or LD_LIBRARY_PATH env and maybe add it to multiPkgs instead of targetPkgs as described here

I hope this gives some ideas for people facing related problems…