Fatal Error when typing import janus_swi as janus (Python)

Hello,
this afternoon I updated some old ports and I got SWI-Prolog’s latest release (9.1.21) and I also got Python’s most recent version (3.12.1). I reinstalled some packages/modules to run with the new Python version/interpreter. I reinstalled and updated the janus-swi package as well, but when I try to import it, I get this “Fatal Error” message (while all works fine with Python3.11.7):

Python 3.12.1 (main, Dec 17 2023, 13:42:47) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import janus_swi as janus
Fatal Python error: PyImport_AppendInittab: PyImport_AppendInittab() may not be called after Py_Initialize()
Python runtime state: initialized

Current thread 0x00000001dd54d000 (most recent call first):
  File "/Users/marcobachini/Library/Python/3.12/lib/python/site-packages/janus_swi/__init__.py", line 18 in <module>
  File "<frozen importlib._bootstrap>", line 488 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 994 in exec_module
  File "<frozen importlib._bootstrap>", line 935 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1331 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1360 in _find_and_load
  File "<stdin>", line 1 in <module>

Extension modules: janus_swi._swipl (total: 1)
zsh: abort      python

It seems to be a Python error, so maybe one should ask in another forum?. Does anyone have a clue if and how I can work around this issue?
Thanks

Seems something changed in the embedding interface. Python has a very extensive C API, but unfortunately it is not very stable. Things are added (ok) and removed/modified regularly. Using Python from Prolog works as expected. At least, it does for me.

I’ll have a look.

1 Like

It was initializing the Python module twice when loaded from Python. Apparently that worked up to 3.11, but raised an error now. Once is good enough :slight_smile:

Please try the new version. Uploaded to PyPi as janus-swi · PyPI Works for me on MacOS using Macport Python 3.12 and SWI-Prolog 9.1.21:

pip3 install --upgrade janus_swi

Now, it refused to upgrade 1.1.0 to 1.1.1, so only removing it using pip3 uninstall janus_swi followed by the installation worked. Possibly the PyPi index needs some time?

1 Like

Thanks so much. I’ll try this

PS: You’re “blazing fast”, Jan :smiley: