devbox: [Bug]: ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory

Current Behavior (bug) When using Python packages via requirements.txt, this time the package is ortools.

This bug was related to #710 and #760. LD_LIBRARY_PATH is /home/tubo/Sync/Projects/radscheduler/.devbox/nix/profile/default/lib

Content of LD_LIBRARY_PATH is:

libecpg.so       libecpg_compat.so       libpgcommon.a        libpgport_shlib.a     libpython3.so  python3.11
libecpg.so.6     libecpg_compat.so.3     libpgcommon_shlib.a  libpython3.11.so      pgxs           
libecpg.so.6.14  libecpg_compat.so.3.14  libpgport.a          libpython3.11.so.1.0  pkgconfig   

Error messages:

============================================================ test session starts =============================================================
platform linux -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0
django: settings: radscheduler.settings (from env)
rootdir: /home/tubo/Sync/Projects/radscheduler/radscheduler
configfile: pytest.ini
plugins: django-4.5.2
collected 0 items / 1 error                                                                                                                  

=================================================================== ERRORS ===================================================================
_______________________________________________________ ERROR collecting core/tests.py _______________________________________________________
ImportError while importing test module '/home/tubo/Sync/Projects/radscheduler/radscheduler/core/tests.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/nix/store/xlpbkwgf4nrnr56a3r0k0r32jxlxyf59-python3-3.11.4/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
radscheduler/core/tests.py:2: in <module>
    from .core import model
radscheduler/core/core.py:1: in <module>
    from ortools.sat.python import cp_model
../../../Projects/radscheduler/.devbox/virtenv/python311Packages.pip/.venv/lib/python3.11/site-packages/ortools/sat/python/cp_model.py:56: in <module>
    from ortools.sat.python import swig_helper
E   ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
========================================================== short test summary info ===========================================================
ERROR radscheduler/core/tests.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================== 1 error in 0.15s ==============================================================

Expected Behavior (fix) Running pytest should not have this error.

Additional context

OS: KDE Neon (Ubuntu 22.04) Devbox version: 0.5.5 to 0.5.7 devbox.json:

{
  "packages": [
    "python@latest",
    "python311Packages.pip@latest",
    "openssl@latest",
    "postgresql@latest",
    "python311Packages.numpy@latest"
  ],
  "env": {
    "DJANGO_SETTINGS_MODULE": "radscheduler.settings",
    "PGPORT": "5434"
  },
  "shell": {
    "init_hook": [
      ". $VENV_DIR/bin/activate",
      "pip install -r requirements.txt --use-pep517"
    ],
    "scripts": {
      "create_db": [
        "echo \"Creating DB\"",
        "dropdb --if-exists rs_db",
        "createdb rs_db",
        "psql rs_db -c \"CREATE USER rs_user WITH PASSWORD 'secretpassword';\"",
        "python radscheduler/manage.py makemigrations",
        "python radscheduler/manage.py migrate"
      ],
      "makemigrations": "radscheduler/manage.py makemigrations",
      "migrate": "radscheduler/manage.py migrate",
      "server": "radscheduler/manage.py runserver",
      "test": "pytest radscheduler"
    }
  }
}

requirements.txt:

django==4.2.2
psycopg2==2.9.5
sqlparse==0.4.4
asgiref==3.6.0
pytest==7.4.0
pytest-django==4.5.2
ortools==9.6.2534

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 29 (3 by maintainers)

Most upvoted comments

@aacebedo thank you ! @gcurtis and I just looked at this. We added patch_glibc: true to librsvg.

This exposed a couple of issues:

  1. A bug in the current implementation. The patch_glibc was only working for one package. The fix for that is straightforward.
  2. We still do run into an error executing convert. The error has to do with a libpango not finding a g_memdup2 symbol. The root cause of that appears to be that there’s a version mismatch with a different library called glib (https://gitlab.gnome.org/GNOME/glib/). We need to investigate a good fix for this, but sadly it’ll take a bit of time 😦. Will circle back when we have some more news.

Thanks to you both looking into this ! I’ll continue to watch the issue and test fixes if it can help to solve this issue.

@aacebedo thank you ! @gcurtis and I just looked at this. We added patch_glibc: true to librsvg.

This exposed a couple of issues:

  1. A bug in the current implementation. The patch_glibc was only working for one package. The fix for that is straightforward.
  2. We still do run into an error executing convert. The error has to do with a libpango not finding a g_memdup2 symbol. The root cause of that appears to be that there’s a version mismatch with a different library called glib (https://gitlab.gnome.org/GNOME/glib/). We need to investigate a good fix for this, but sadly it’ll take a bit of time 😦. Will circle back when we have some more news.

@aacebedo sorry for the delay. After trying out the steps, I think I understand the problem. In my prototype, I’ve patched python and librsvg using the local flake. Those do work.

You are trying convert that came from the imagemagick nix package. You’ll need to patch that via a local flake (as I illustrated with python or librsvg). We don’t patch all packages automatically to be conservative, as I explain at the end of the README of https://github.com/savil/devbox-issue-1276, and until we get some validating feedback from real world projects.

Or better, I’d suggest using Devbox 0.8.0-dev and modifying the devbox.json to specify patch_glibc:true for whichever packages are hitting the libc errors. Let us know if that works, and thanks for pursuing this with us!

@aacebedo I was discussing a similar issue with a user on Discord (is that you as well?).

In that case, something like this helped:

# main.py
import matplotlib

def main():
    print("hello world")

main()

# requirements.txt
matplotlib==3.7.2

# devbox.json
{
  "packages": [
    "python310@latest",
    "python310Packages.pip@latest",
    "drawio@latest",
    "librsvg@latest",
    "github:nixos/nixpkgs/6b70761ea8c896aff8994eb367d9526686501860#stdenv.cc.cc.lib"
  ],
  "shell": {
    "init_hook": [
      "export DEVBOX_DEBUG=1",
      ". $VENV_DIR/bin/activate",
      "pip install -q -r requirements.txt"
    ]
  },
  "nixpkgs": {
    "commit": "73e1976309fc789706b9f306407e9e7622a57d25"
  }
}


# devbox.lock
{
  "lockfile_version": "1",
  "packages": {
    "drawio@latest": {
      "last_modified": "2023-09-10T10:53:27Z",
      "resolved": "github:NixOS/nixpkgs/78058d810644f5ed276804ce7ea9e82d92bee293#drawio",
      "source": "devbox-search",
      "version": "21.6.8"
    },
    "github:nixos/nixpkgs/6b70761ea8c896aff8994eb367d9526686501860#stdenv.cc.cc.lib": {},
    "librsvg@latest": {
      "last_modified": "2023-09-10T10:53:27Z",
      "resolved": "github:NixOS/nixpkgs/78058d810644f5ed276804ce7ea9e82d92bee293#librsvg",
      "source": "devbox-search",
      "version": "2.56.3"
    },
    "python310@latest": {
      "last_modified": "2023-02-24T18:08:35Z",
      "plugin_version": "0.0.1",
      "resolved": "github:NixOS/nixpkgs/806075be2bdde71895359ed18cb530c4d323e6f6#python3",
      "source": "devbox-search",
      "version": "3.10.9"
    },
    "python310Packages.pip@latest": {
      "last_modified": "2023-09-10T10:53:27Z",
      "plugin_version": "0.0.1",
      "resolved": "github:NixOS/nixpkgs/78058d810644f5ed276804ce7ea9e82d92bee293#python310Packages.pip",
      "source": "devbox-search",
      "version": "23.2.1"
    }
  }

The reasoning is:

  • The error seen was: Original error was: /nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6: version 'GLIBC_2.36' not found (required by /tmp/test/.devbox/nix/profile/default/lib/libstdc++.so.6)
  • What’s happening is that that the stdenv.cc.cc.lib is expecting a GLIBC 2.36, but the code executed by the python binary (either directly, or indirectly via the matplotlib -> numpy dependencies) is linked against GLIBC 2.35.
  • I searched https://www.nixhub.io/packages/glibc and version 2.35-224 is from nixpkgs/6b70761ea8c896aff8994eb367d9526686501860#glibc
  • So, to try fixing it I replaced stdenv.cc.cc.lib with github:nixos/nixpkgs/6b70761ea8c896aff8994eb367d9526686501860#stdenv.cc.cc.lib

Hey @Tubo, I’m working on recreating this. Do you have an example of the test you’re trying to run with pytest that triggers this issue?

It’s dead simple:

from django.test import TestCase

def test_pytest():
    assert False

One thing that might work is running devbox add stdenv.cc.cc.lib, which should add the libstdc++ libraries to your dev environment.