python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Unable to use the library on RHEL8 - _xxsubinterpreters.

Open skarndev opened this issue 3 months ago • 5 comments

Hi. I am struggling to use the library on python3.12 in a RHEL8 environment (Red Hat Linux). dependency-injector version is 4.48.1.

The code to reproduce is:

from dependency_injector import providers, containers

The error is ModuleNotFound("_xxsubinterpreters")

During a brief investigation I found that the problem is related to Cython files containing code attempting to load an experimental module _xxsubinterpeters in Python3.12

#if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x03090000
static PY_INT64_T __Pyx_GetCurrentInterpreterId(void) {
    {
        PyObject *module = PyImport_ImportModule("_interpreters"); // 3.13+ I think
        if (!module) {
            PyErr_Clear(); // just try the 3.8-3.12 version
            module = PyImport_ImportModule("_xxsubinterpreters");
            if (!module) goto bad;
        }
        PyObject *current = PyObject_CallMethod(module, "get_current", NULL);
        Py_DECREF(module);
        if (!current) goto bad;
        if (PyTuple_Check(current)) {
            PyObject *new_current = PySequence_GetItem(current, 0);
            Py_DECREF(current);
            current = new_current;
            if (!new_current) goto bad;
        }
        long long as_c_int = PyLong_AsLongLong(current);
        Py_DECREF(current);
        return as_c_int;
    }
  bad:
    PySys_WriteStderr("__Pyx_GetCurrentInterpreterId failed. Try setting the C define CYTHON_PEP489_MULTI_PHASE_INIT=0\n");
    return -1;
}
#endif

This module is indeed available on stock Python on my local machine (MacOS, homebrew install) and is also available in python3.12 coming from Debian packages. It is not available on RHEL builds though.

I am not sure if this is an issue of Cython itself, or it is the .whl that is not compatible. If we rebuild locally, what settings should we use?

skarndev avatar Aug 13 '25 13:08 skarndev