The problem seems to be a dynamic linking problem that your python program fail to find the zlib artifact, adding the path to LD_LIBRARY_PATH
will work.
Example shell.nix
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell rec {
buildInputs = [
pkgs.python3
pkgs.poetry
pkgs.zlib
];
shellHook = ''
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath buildInputs}:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib.outPath}/lib:$LD_LIBRARY_PATH"
'';
}
The above shell can fail actually because I don’t know which nixpkgs channel you’re using. Would be nice if this can help you.