I'm working on a project where I use pyswip to integrate SWI-Prolog with Python. As someone new to Prolog programming, I've encountered an assertion failure when attempting to consult a Prolog file using pyswip. The error occurs specifically at the prolog.consult("/mnt/data/Dynamic_aci_assignment_PS2.pl") line in my Python script. My environment uses SWI-Prolog version 9.2.2 and pyswip version 0.2.10 on a Linux system.
from pyswip import Prolog
prolog = Prolog()
prolog.consult("test.pl")
test.pl file contains -
% test.pl
likes(john, pizza).
I am getting the folllowing error -
/home/agaonsindhe/Downloads/yes/bin/python /home/agaonsindhe/Desktop/codebase/python/mtech/aci/assignment_2/sample_prolog_run.py
[Thread 1 (main) at Sun Mar 17 13:48:59 2024] ./src/pl-fli.c:2674: PL_put_chars: Assertion failed: 0
C-stack trace labeled "assert_fail":
[0] PL_changed_cwd() at ??:? [0x75f3db6dcb3b]
[1] _PL_atoms() at ??:? [0x75f3db6b989e]
[2] PL_put_chars() at ??:? [0x75f3db6cbe19]
[3] ffi_call_unix64() at :? [0x75f3dc217052]
[4] ffi_call_int() at ffi64.c:? [0x75f3dc215925]
[5] ffi_call() at ??:? [0x75f3dc21606e]
[6] _call_function_pointer() at /usr/local/src/conda/python-3.11.5/Modules/_ctypes/callproc.c:944 [0x75f3dbfd52e4]
[7] PyCFuncPtr_call() at /usr/local/src/conda/python-3.11.5/Modules/_ctypes/_ctypes.c:4201 [0x75f3dbfde4ce]
[8] /home/agaonsindhe/Downloads/yes/bin/python(_PyObject_MakeTpCall+0x254) [0x502d54]
[9] /home/agaonsindhe/Downloads/yes/bin/python(_PyEval_EvalFrameDefault+0x755) [0x50f025]
[10] /home/agaonsindhe/Downloads/yes/bin/python(+0x19b8c7) [0x59b8c7]
[11] /home/agaonsindhe/Downloads/yes/bin/python(+0x12bc6b) [0x52bc6b]
[12] /home/agaonsindhe/Downloads/yes/bin/python(PyObject_Vectorcall+0x31) [0x51bff1]
[13] /home/agaonsindhe/Downloads/yes/bin/python(_PyEval_EvalFrameDefault+0x755) [0x50f025]
[14] /home/agaonsindhe/Downloads/yes/bin/python(+0x1c82ce) [0x5c82ce]
[15] /home/agaonsindhe/Downloads/yes/bin/python(PyEval_EvalCode+0x9f) [0x5c79cf]
[16] /home/agaonsindhe/Downloads/yes/bin/python(+0x1e8807) [0x5e8807]
[17] /home/agaonsindhe/Downloads/yes/bin/python(+0x1e4e40) [0x5e4e40]
[18] /home/agaonsindhe/Downloads/yes/bin/python(+0x1f9132) [0x5f9132]
[19] /home/agaonsindhe/Downloads/yes/bin/python(_PyRun_SimpleFileObject+0x19f) [0x5f871f]
[20] /home/agaonsindhe/Downloads/yes/bin/python(_PyRun_AnyFileObject+0x43) [0x5f8473]
[21] /home/agaonsindhe/Downloads/yes/bin/python(Py_RunMain+0x2ee) [0x5f2fee]
[22] /home/agaonsindhe/Downloads/yes/bin/python(Py_BytesMain+0x39) [0x5b6e19]
[23] __libc_start_call_main() at ./csu/../sysdeps/x86/libc-start.c:74 [0x75f3dc028150]
[24] call_init() at ./csu/../csu/libc-start.c:128 [0x75f3dc028209]
[25] /home/agaonsindhe/Downloads/yes/bin/python(+0x1b6c6f) [0x5b6c6f]
Prolog stack:
(null)
Process finished with exit code 134 (interrupted by signal 6:SIGABRT)
What I've tried:
What could be causing this assertion failure in SWI-Prolog when consulting a Prolog file via pyswip? As I am new to Prolog programming, any insights on potential fixes, workarounds, or even general advice on integrating Prolog with Python would be greatly appreciated.
I think that the problem is with PYSWIP 2.10. I was getting exactly the same error using Python3.10.12 and SWIPL 9.2.4. Changing to PYSWIP 2.09 resolved the problem. I agree with the above suggestion that you consider using JANUS-SWI. I have found it to be much faster for my application.