# Fatal Error when typing import janus\_swi as janus (Python)

**URL:** <https://swi-prolog.discourse.group/t/fatal-error-when-typing-import-janus-swi-as-janus-python/7077>\
**Category:** Tools\
**Created:** [December 17, 2023, 3:16pm UTC](https://swi-prolog.discourse.group/t/fatal-error-when-typing-import-janus-swi-as-janus-python/7077 "2023-12-17T15:16:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon419083](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anon419083](https://swi-prolog.discourse.group/u/anon419083)\
**Post date:** [December 17, 2023, 3:16pm UTC](https://swi-prolog.discourse.group/t/fatal-error-when-typing-import-janus-swi-as-janus-python/7077/1 "2023-12-17T15:16:45Z")

</div>

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):

```prolog
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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 17, 2023, 4:15pm UTC](https://swi-prolog.discourse.group/t/fatal-error-when-typing-import-janus-swi-as-janus-python/7077/2 "2023-12-17T16:15:39Z")

</div>

> [@anon419083](#):
>
> 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?

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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 17, 2023, 4:38pm UTC](https://swi-prolog.discourse.group/t/fatal-error-when-typing-import-janus-swi-as-janus-python/7077/3 "2023-12-17T16:38:36Z")

</div>

> [@jan](#):
>
> I’ll have a look.

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 🙂

Please try the new version. Uploaded to PyPi as [janus-swi · PyPI](https://pypi.org/project/janus-swi/1.1.1/) 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?

---

<div class="post-metadata">

**Author:** ![anon419083](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anon419083](https://swi-prolog.discourse.group/u/anon419083)\
**Post date:** [December 17, 2023, 4:42pm UTC](https://swi-prolog.discourse.group/t/fatal-error-when-typing-import-janus-swi-as-janus-python/7077/4 "2023-12-17T16:42:03Z")

</div>

Thanks so much. I’ll try this

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