Easy Prolog installation on Windows, Linux, macOS

Kai Brooks
3 min readJan 14, 2020

Installing SWI Prolog with its web UI and running some test code. This system is functionally similar to how Jupyter Notebook runs, except with Prolog.

Install Docker

Install Docker (requires a free account). This installation is a standalone on Windows and macOS, but requires the command line on Linux:

Pull the Prolog image

docker pull swipl/swish

We only need to pull this once. This version includes the web interface!

Run the image

docker run -it -p 3050:3050 --name prolog swipl/swish

Anytime we want to work in Prolog, we run the above. We can then access the web GUI by pointing our browser to http://localhost:3050

Prolog Web Interface

A Sample Program

Click on Create a Program here. The interface changes to a program on the left, and the query box on the right.

If we clicked on Create a Notebook here instead, the prolog interface would resemble Jupyter Notebook, and let us run cells of code individually (similar to Jupyter Notebook for Python).

In the left, program section, type:

loves(vincent, mia).
loves(marcellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
jealous(X, Y) :-
loves(X, Z),
loves(Y, Z).

This sets up the logic and axioms of our program. In the right, query section, type:

loves(X, mia).

and hit Run. This query asks, who loves Mia? From up top, we see that it’s Vincent and Marcellus. Our output follows:

Who loves Mia?

Here we only see Vincent. To see the rest, click the next button:

Clicking next shows the rest of the output

For a different query, run:

jealous(X,Y).

Click through next (or the numbers) to reveal the entire output:

A love dodecahedron

The final window looks like so:

Output for both queries

Note that Prolog is case-sensitive, so if we define X with a capital, we need to use a capital in the query.

In addition, we can still run Prolog from the command line:

Prolog in the CLI

Stopping the server

The Prolog server stays open until we exit it with Control+C twice in the command line.

List of errors and fixes

docker: Error response from daemon: driver failed programming external connectivity on endpoint …: Bind for 0.0.0.0:3050 failed: port is already allocated.

Prolog is still running the server. You can access it at http://localhost:3050.

If you want to stop Prolog but closed the window and can’t use the Control+C method, here’s some options:

This command will stop all Docker containers:

docker rm -f $(docker ps -a -q)

If you want to close a single container, use:

docker container ls

to display all running containers. Take note of the Container ID, then run

docker stop CONTAINERID
Stopping a container. Note that we only need the first character(s) of the container ID

--

--