Skip to content

Segfaults when importing python-libsbml with python3.11 and -Werror #40

@dweindl

Description

@dweindl

Importing the current manylinux Python 3.11 wheel (python_libsbml-5.20.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl) with Python 3.11.11 on Ubuntu with -Werror (common under pytest) results in a segfault.

After creating a new virtual environment with Python 3.11 and installing python-libsbml from PyPI:

# works
$ python -c "import libsbml"

$ python -Werror -c "import libsbml"
Fatal Python error: Segmentation fault

Current thread 0x00007003ce02eb80 (most recent call first):
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1233 in create_module
  File "<frozen importlib._bootstrap>", line 573 in module_from_spec
  File "<frozen importlib._bootstrap>", line 676 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1147 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1176 in _find_and_load
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1232 in _handle_fromlist
  File "/home/dweindl/deleteme/lib/python3.11/site-packages/libsbml/__init__.py", line 25 in <module>
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 940 in exec_module
  File "<frozen importlib._bootstrap>", line 690 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1147 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1176 in _find_and_load
  File "<string>", line 1 in <module>
Segmentation fault (core dumped)

# works
$ python -Wall -c "import libsbml"
<frozen importlib._bootstrap>:241: DeprecationWarning: builtin type SwigPyPacked has no __module__ attribute
<frozen importlib._bootstrap>:241: DeprecationWarning: builtin type SwigPyObject has no __module__ attribute
<frozen importlib._bootstrap>:241: DeprecationWarning: builtin type swigvarlink has no __module__ attribute

This is a known problem with swig4.3 (swig/swig#3061, swig/swig#2881).

Here a workaround I used elsewhere: https://github.com/AMICI-dev/AMICI/blob/2753e10242fb2393ead4d0bddfd44bdc5e9ef27f/python/sdist/amici/__init__.py#L106-L116. (I.e., catching the warnings shown above with -Wall when importing the extension module.)

EDIT: This also affects Python 3.10, but not Python 3.12 and 3.13.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions