Running prolog on a mac
Asked Answered
S

6

37

I am having the hardest trouble trying to run SWI-prolog on my Mac.

When I type:

/opt/bin/local/swipl

I get an error saying:

/opt/local/bin/swipl: No such file or directory

When I just type "swipl" I get:

swipl: command not found

I've tried this on both terminal and XQuartz. I've even gone into

/Applications/SWI-Prolog.app/Contents/MacOS

to see if that would do anything, however the prolog "Welcome" text never appears. Quite possibly the closest I ever got it to work was when I typed "pl" when inside the MacOS folder. However I was left with my terminal doing nothing and had to use Crtl-D.

Is there something I'm doing wrong? Did I install something incorrectly?

I'm running on a Mac OS X 10.9.1 Mavericks. I placed the SWI-Prolog application into my application folder and I also downloaded XQuartz per recommendation by the website.

Sedulous answered 6/2, 2014 at 8:46 Comment(2)
what version of SWI are you working with?Lampion
Also, have you tried adding /Applications/SWI-Prolog.app/Contents/MacOs to your PATH? I believe this is what I have done, since the swipl executable is located therein.Lampion
S
90

If you have Homebrew installed, you can simply run

brew install swi-prolog

from Terminal, which will build it from source in one command.

You can then run the interpreter using swipl.

Sweyn answered 28/5, 2014 at 6:13 Comment(4)
Also, I first needed to brew tap homebrew/x11.Jane
I've removed the 'brew tap' command because it's not necessary anymore, homebrew changed the location of the formula.Diachronic
I get Error: No available formula for swi-prolog. Even after first running brew tap homebrew/x11Plantaineater
I want the older version of swi-prolog, what should I do?Platysma
F
14

There are three sensible ways of installing SWI-Prolog on MacOS X, in increasing order of complexity:

  1. Download the SWI-Prolog application. In this case, you just download a disk image, open it, and drag the application to your disk (e.g. to your Applications folder. You use the application as any other application by double-clicking on its icon. If you want to also use the binary inside the application bundle, add the Contents/MacOS directory inside it to your system path (for example, assuming that you copied the SWI-Prolog application to your applications folder, do export PATH=/Applications/SWI-Prolog.app/Contents/MacOS:$PATH in your shell configuration file).

  2. Using MacPorts. Assuming it's installed and up-to-date, simply type either sudo port install swi-prolog for the stable version or sudo port install swi-prolog-devel for the development version. Replace sudo port install by sudo port -u upgrade when upgrading the installed version. It you're already using MacPorts, then /opt/local/bin should already be in your system path. Type echo $PATH in a Terminal window to check.

  3. Compiling from sources. In this case, download the source archive, uncompress it, and follow the instructions in the README.MacOSX file.

Flabellate answered 6/2, 2014 at 11:20 Comment(2)
I did the first option, and I get a window where I can put in prolog commands, with the familiar ?-. So that's good, but I'm having a hard time loading a pl file. Usually you can do [fileName]. but this doesn't work, I'm guessing because it doesn't know where to look for this file. Any idea how I fix that?Esbjerg
Call the predicate pwd/0to check the current directory. You can always change it by calling the cd/1 predicate. Or give a relative or absolute file path when consulting a file.Flabellate
J
6

The OSX EI Captian has this command for swi-prolog installation

brew install homebrew/x11/swi-prolog
Jacobs answered 2/11, 2015 at 23:22 Comment(1)
Because of some changes on homebrews side, this doesn't work anymore. See my answer.Diachronic
D
6

Homebrew has moved swi-prolog to the top a few days ago and because of this, the other answers are not valid anymore. The reason for that: the swi-prolog formula was located in the x11 bottle but the x11 dependency is only optional.

As of today, to install swi-prolog with homebrew, simply do:

brew install swi-prolog

If you've installed it from the x11 bottle before, consider to uninstall an reinstall from the new location. Otherwise you might run into errors when updating/upgrading.

Diachronic answered 19/5, 2016 at 5:11 Comment(1)
I used this command, It downloaded and I get the Welcome prompt but how do I create files?Palate
H
5

If you download the SWI-Prolog application into your /Applications folder, then add this to your .bash_profile:

export PATH="/Applications/SWI-Prolog.app/Contents/MacOS:$PATH"

The swipl binary lives in that MacOS directory. (Don't forget to source ~/.bash_profile after)

Haire answered 23/11, 2017 at 17:50 Comment(0)
G
1

There's now a handy docker image.

Guthrey answered 20/6, 2019 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.