Bug 2050139 - librealsense fails to build with Python 3.11: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
Summary: librealsense fails to build with Python 3.11: error: 'PyFrameObject' {aka 'st...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: librealsense
Version: 36
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Till Hofmann
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 2098740 (view as bug list)
Depends On:
Blocks: PYTHON3.11 F37FTBFS F37FailsToInstall
TreeView+ depends on / blocked
 
Reported: 2022-02-03 10:49 UTC by Tomáš Hrnčiar
Modified: 2022-07-17 09:27 UTC (History)
3 users (show)

Fixed In Version: librealsense-2.50.0-2.fc37
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-07-17 09:27:09 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Tomáš Hrnčiar 2022-02-03 10:49:25 UTC
librealsense fails to build with Python 3.11.0a4.

/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/cast.h: In function 'std::string pybind11::detail::error_string()':
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/cast.h:441:38: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
  441 |                 "  " + handle(frame->f_code->co_filename).cast<std::string>() +
      |                                      ^~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/cast.h:441:75: error: expected primary-expression before '>' token
  441 |                 "  " + handle(frame->f_code->co_filename).cast<std::string>() +
      |                                                                           ^
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/cast.h:441:77: error: expected primary-expression before ')' token
  441 |                 "  " + handle(frame->f_code->co_filename).cast<std::string>() +
      |                                                                             ^
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/cast.h:443:31: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
  443 |                 handle(frame->f_code->co_name).cast<std::string>() + "\n";
      |                               ^~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/cast.h:443:64: error: expected primary-expression before '>' token
  443 |                 handle(frame->f_code->co_name).cast<std::string>() + "\n";
      |                                                                ^
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/cast.h:443:66: error: expected primary-expression before ')' token
  443 |                 handle(frame->f_code->co_name).cast<std::string>() + "\n";
      |                                                                  ^
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h: In constructor 'pybind11::gil_scoped_acquire::gil_scoped_acquire()':
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1741:58: warning: 'void* PyThread_get_key_value(int)' is deprecated [-Wdeprecated-declarations]
 1741 |         tstate = (PyThreadState *) PyThread_get_key_value(internals.tstate);
      |                                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/python3.11/pythread.h:114:39: note: declared here
  114 | Py_DEPRECATED(3.7) PyAPI_FUNC(void *) PyThread_get_key_value(int key);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1753:35: warning: 'int PyThread_set_key_value(int, void*)' is deprecated [-Wdeprecated-declarations]
 1753 |             PyThread_set_key_value(internals.tstate, tstate);
      |             ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/python3.11/pythread.h:112:36: note: declared here
  112 | Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_set_key_value(int key,
      |                                    ^~~~~~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h: In member function 'void pybind11::gil_scoped_acquire::dec_ref()':
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1792:38: warning: 'void PyThread_delete_key_value(int)' is deprecated [-Wdeprecated-declarations]
 1792 |             PyThread_delete_key_value(detail::get_internals().tstate);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/python3.11/pythread.h:115:37: note: declared here
  115 | Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyThread_delete_key_value(int key);
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h: In constructor 'pybind11::gil_scoped_release::gil_scoped_release(bool)':
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1820:39: warning: 'int PyThread_set_key_value(int, void*)' is deprecated [-Wdeprecated-declarations]
 1820 |                 PyThread_set_key_value(key, nullptr);
      |                 ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/python3.11/pythread.h:112:36: note: declared here
  112 | Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_set_key_value(int key,
      |                                    ^~~~~~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h: In destructor 'pybind11::gil_scoped_release::~gil_scoped_release()':
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1833:35: warning: 'int PyThread_set_key_value(int, void*)' is deprecated [-Wdeprecated-declarations]
 1833 |             PyThread_set_key_value(key, tstate);
      |             ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
/usr/include/python3.11/pythread.h:112:36: note: declared here
  112 | Py_DEPRECATED(3.7) PyAPI_FUNC(int) PyThread_set_key_value(int key,
      |                                    ^~~~~~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h: In function 'pybind11::function pybind11::get_type_overload(const void*, const detail::type_info*, const char*)':
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1890:49: error: 'PyThreadState' {aka 'struct _ts'} has no member named 'frame'; did you mean 'cframe'?
 1890 |     PyFrameObject *frame = PyThreadState_Get()->frame;
      |                                                 ^~~~~
      |                                                 cframe
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1891:43: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
 1891 |     if (frame && (std::string) str(frame->f_code->co_name) == name &&
      |                                           ^~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1892:16: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
 1892 |         frame->f_code->co_argcount > 0) {
      |                ^~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1895:20: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_locals'
 1895 |             frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
      |                    ^~~~~~~~
In file included from /usr/include/python3.11/Python.h:35:
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1895:54: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
 1895 |             frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
      |                                                      ^~~~~~
/usr/include/python3.11/tupleobject.h:27:18: note: in expansion of macro 'PyType_FastSubclass'
   27 |                  PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
      |                  ^~~~~~~~~~~~~~~~~~~
/usr/include/python3.11/object.h:140:30: note: in expansion of macro '_PyObject_CAST_CONST'
  140 | #define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST_CONST(ob))
      |                              ^~~~~~~~~~~~~~~~~~~~
/usr/include/python3.11/tupleobject.h:27:38: note: in expansion of macro 'Py_TYPE'
   27 |                  PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
      |                                      ^~~~~~~
/usr/include/python3.11/cpython/tupleobject.h:19:35: note: in expansion of macro 'PyTuple_Check'
   19 | #define _PyTuple_CAST(op) (assert(PyTuple_Check(op)), (PyTupleObject *)(op))
      |                                   ^~~~~~~~~~~~~
/usr/include/python3.11/cpython/tupleobject.h:23:34: note: in expansion of macro '_PyTuple_CAST'
   23 | #define PyTuple_GET_ITEM(op, i) (_PyTuple_CAST(op)->ob_item[i])
      |                                  ^~~~~~~~~~~~~
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1895:30: note: in expansion of macro 'PyTuple_GET_ITEM'
 1895 |             frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
      |                              ^~~~~~~~~~~~~~~~
In file included from /usr/include/python3.11/tupleobject.h:39,
                 from /usr/include/python3.11/Python.h:57:
/builddir/build/BUILD/librealsense-2.40.0/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:1895:54: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
 1895 |             frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
      |                                                      ^~~~~~

Changes of the private PyFrameObject structure members.

While the documentation notes that the fields of PyFrameObject are subject to change at any time, they have been stable for a long time and were used in several popular extensions. In Python 3.11, the frame struct was reorganized to allow performance optimizations. Rather than reading the fields directly, extensions should use functions:
    f_code: removed, use PyFrame_GetCode() instead. Warning: the function returns a strong reference, need to call Py_DECREF().
    f_back: changed (see below), use PyFrame_GetBack().
    f_builtins: removed, use PyObject_GetAttrString(frame, "f_builtins").
    f_globals: removed, use PyObject_GetAttrString(frame, "f_globals").
    f_locals: removed, use PyObject_GetAttrString(frame, "f_locals").
    f_lasti: removed, use PyObject_GetAttrString(frame, "f_lasti").

The following fields were removed entirely, as they were details of the old implementation:
    f_valuesstack
    f_stackdepth
    f_gen
    f_iblock
    f_state
    f_blockstack
    f_localsplus

The Python frame object is now created lazily. A side effect is that the f_back member must not be accessed directly, since its value is now also computed lazily. The PyFrame_GetBack() function must be called instead.

https://docs.python.org/3.11/whatsnew/3.11.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.11/fedora-rawhide-x86_64/03271275-librealsense/

For all our attempts to build librealsense with Python 3.11, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/package/librealsense/

Testing and mass rebuild of packages is happening in copr. You can follow these instructions to test locally in mock if your package builds with Python 3.11:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/

Let us know here if you have any questions.

Python 3.11 is planned to be included in Fedora 37. To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.11.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires), so if this package is required a lot, it's important for us to get it fixed soon.
We'd appreciate help from the people who know this package best, but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Ben Cotton 2022-02-08 20:17:51 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle.
Changing version to 36.

Comment 2 Miro Hrončok 2022-06-20 10:15:13 UTC
*** Bug 2098740 has been marked as a duplicate of this bug. ***

Comment 3 Miro Hrončok 2022-06-27 14:53:22 UTC
Hello,

This is the first reminder (step 3 from https://docs.fedoraproject.org/en-US/fesco/Fails_to_build_from_source_Fails_to_install/#_package_removal_for_long_standing_ftbfs_and_fti_bugs).

If you know about this problem and are planning on fixing it, please acknowledge so by setting the bug status to ASSIGNED. If you don't have time to maintain this package, consider orphaning it, so maintainers of dependent packages realize the problem.


Note You need to log in before you can comment on or make changes to this bug.