How to install and use SWI-Prolog in Jupyter Notebooks

Hi and hello to the Community,
for educational purposes I would like to use Jupyter Notebooks also for Prolog. I installed the Calysto Kernel but it seems to have a major issue. The SWI-prolog-Kernel repository just wants backports.tempfile to be installed, which searched for and installed. Not sure if this is the right one? But the Kernel does not appear in the list of Kernels and I don´t know how to fix ad to use this. Did anyone work with this already and can give me some directions how this works? Any help appreceated!
The SWI Repository:

1 Like


I wanted to run some Prolog code, and decided to use Jupyter notebooks too. Searching I found this post where you mention the madmax2012/SWI-Prolog-Kernel. I had found this other repository, based on the madmax2012/SWI-Prolog-Kernel too, but I guess with some extra work targodan/jupyter-swi-prolog.

But after some more searching the web, I found this post Teaching OCaml and Prolog through Jupyter Notebooks from Jan/2019. The author forked targodan/jupyter-swi-prolog and added yet more things (really small changes, but look like they could be useful).

I couldn’t find much after that, but since this was the fork of the fork of madmax2012/SWI-Prolog-Kernel, and I couldn’t find other active projects (or more recent), I had a go, and succeeded in running some basic Prolog in a notebook. Here’s what I did on Ubuntu LTS 22.04 and Conda 4.13, Python 3.9:

conda create -n prolog
conda activate prolog
conda install pip
pip install jswipl
cd ~/.local/share/jupyter/kernels
mkdir jswipl && cd jswipl
mkdir -p ~/Development/prolog/workspace/notebooks-001
cd ~/Development/prolog/workspace/notebook-001
conda install jupyterlab
jupyter lab

At this point, just create a new SWI Prolog notebook, paste the example from the docs, and CTRL+ENTER or press Run.

mortal(X) :- man(X).

?- mortal(socrates).
?- mortal(X).
?- mortal(bob).

Hope it helps.