33

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.

false
  • 10,264
  • 13
  • 101
  • 209
user3278629
  • 331
  • 1
  • 3
  • 3
  • what version of SWI are you working with? – Shon Feb 06 '14 at 09:06
  • 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. – Shon Feb 06 '14 at 09:07

6 Answers6

87

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.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
Simon Hartcher
  • 3,400
  • 3
  • 30
  • 34
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.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • 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? – The Oddler Oct 09 '14 at 10:57
  • 1
    Call the predicate `pwd/0`to 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. – Paulo Moura Oct 09 '14 at 11:20
6

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

brew install homebrew/x11/swi-prolog
Mounika Kakarla
  • 124
  • 1
  • 3
5

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.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
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)

Zhanwen Chen
  • 1,295
  • 17
  • 21
1

There's now a handy docker image.

bhurlow
  • 2,019
  • 2
  • 16
  • 14