devenv: `ImportError` when running a Python package that includes share libraries
Describe the bug
Python packages installed from pip cannot find libstdc++.so.6
To reproduce
Given the flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
systems.url = "github:nix-systems/default";
devenv.url = "github:cachix/devenv";
};
nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};
outputs = { self, nixpkgs, devenv, systems, ... } @ inputs:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
devShells = forEachSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
# https://devenv.sh/reference/options/
packages = [ pkgs.hello ];
enterShell = ''
python -m grpc_tools.protoc --help
'';
languages.python = {
enable = true;
venv = {
enable = true;
requirements = ''
grpcio-tools
'';
};
};
}
];
};
});
};
}
Run nix develop --impure, then I got the error
$ nix develop --impure
warning: Git tree '/home/atry/devenv-poetry' is dirty
Requirement already satisfied: grpcio-tools in ./.devenv/state/venv/lib/python3.10/site-packages (from -r /nix/store/zl8ljp68qhqs4gd836isanbq6z393arr-requirements.txt (line 1)) (1.56.2)
Requirement already satisfied: grpcio>=1.56.2 in ./.devenv/state/venv/lib/python3.10/site-packages (from grpcio-tools->-r /nix/store/zl8ljp68qhqs4gd836isanbq6z393arr-requirements.txt (line 1)) (1.56.2)
Requirement already satisfied: setuptools in ./.devenv/state/venv/lib/python3.10/site-packages (from grpcio-tools->-r /nix/store/zl8ljp68qhqs4gd836isanbq6z393arr-requirements.txt (line 1)) (65.5.0)
Requirement already satisfied: protobuf<5.0dev,>=4.21.6 in ./.devenv/state/venv/lib/python3.10/site-packages (from grpcio-tools->-r /nix/store/zl8ljp68qhqs4gd836isanbq6z393arr-requirements.txt (line 1)) (4.23.4)
[notice] A new release of pip is available: 23.0.1 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
Traceback (most recent call last):
File "/nix/store/zn2g96d0hhk5h8x7982m2gbbawgwsrvz-python3-3.10.11/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/nix/store/zn2g96d0hhk5h8x7982m2gbbawgwsrvz-python3-3.10.11/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/atry/devenv-poetry/.devenv/state/venv/lib/python3.10/site-packages/grpc_tools/protoc.py", line 20, in <module>
from grpc_tools import _protoc_compiler
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
Version
e91205acb792f6a49ea53ab04c04fbc2a85039cd
This error can be reproduced on both Ubuntu and NixOS
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 4
- Comments: 32 (23 by maintainers)
Here is a demo to solve this issue using
LD_AUDIT: https://github.com/Atry/devenv-ld-floxlibYou can compare the solution with https://github.com/Atry/nix-ld-so-cache-test
I can’t say if the ABI would cause problems, but I can say a statically linked musl with a dynamically linked glibc sounds like a cursed runtime
I used to think that a statically linked musl can coexist with a dynamically linked glibc.
On Tue, Apr 30, 2024 at 2:56 AM Sem Mulder @.***> wrote:
You’re fast! It would also be nice to provide ld-floxlib in Nixpkgs. Also we could patch it to reproduce the
LD_FALLBACK_PATHinterface tooI just realized there is already a way to specify fallback library path in glibc’s dynamic linker: https://github.com/NixOS/nixpkgs/pull/248547#issuecomment-1995469926
I wonder if we could use LD_AUDIT instead of LD_LIBRARY_PATH to support manylinux ABI?
How about
languages.python.nativeDependencies?