我正在开发一个项目,使用 pyswip 将 SWI-Prolog 与 Python 集成。作为 Prolog 编程的新手,我在尝试使用 pyswip 查询 Prolog 文件时遇到了断言失败。该错误特别发生在我的 Python 脚本中的 prolog.consult("/mnt/data/Dynamic_aci_assignment_PS2.pl") 行。我的环境在 Linux 系统上使用 SWI-Prolog 版本 9.2.2 和 pyswip 版本 0.2.10。
from pyswip import Prolog
prolog = Prolog()
prolog.consult("test.pl")
test.pl 文件包含 -
% test.pl
likes(john, pizza).
我收到以下错误 -
/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)
我尝试过的:
通过 pyswip 查询 Prolog 文件时,什么可能导致 SWI-Prolog 中的断言失败?由于我是 Prolog 编程新手,任何有关潜在修复、解决方法甚至将 Prolog 与 Python 集成的一般建议的见解都将不胜感激。
我认为问题出在 PYSWIP 2.10 上。我使用 Python3.10.12 和 SWIPL 9.2.4 遇到了完全相同的错误。更改为 PYSWIP 2.09 解决了该问题。我同意上述建议,您可以考虑使用 JANUS-SWI。我发现它对于我的应用程序来说要快得多。