# Installing SWI-Prolog on Mac OS X with xpce support via homebrew

**URL:** <https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016>\
**Category:** Installing\
**Tags:** how-to\
**Created:** [November 30, 2023, 10:41pm UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016 "2023-11-30T22:41:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![doublec](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/doublec/32/555_2.png) [@doublec](https://swi-prolog.discourse.group/u/doublec)\
**Post date:** [November 30, 2023, 10:41pm UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/1 "2023-11-30T22:41:28Z")

</div>

These are the steps I took to get a version of SWI-prolog built using homebrew with xpce support, so ‘edit’, etc works.

Install XQuartz, the X11 server:

```
brew install --cask xquartz

```

Turn developer mode on so we can edit the swi-prolog formula:

```
brew developer on

```

Download the developer formulae:

```
brew tap homebrew/core

```

Allow installing modified formula:

```
export HOMEBREW_NO_INSTALL_FROM_API=1

```

Edit the swi-prolog formula:

```
brew edit swi-prolog

```

Add the following to the “depends\_on” section:

```
depends_on "freetype"
depends_on "libx11"

```

Change ‘args’ to allow X packages:

```
args = ["-DSWIPL_PACKAGES_JAVA=OFF", "-DSWIPL_PACKAGES_X=ON", "-DCMAKE_INSTALL_RPATH=#{loader_path}"]

```

Exit the editor, saving the changes. Install swi-prolog from source, optionally adding “–head” to get the latest source.

```
brew install swi-prolog --build-from-source --head

```

Run XQuartz from the Mac OS Applications, then start `swipl` with DISPLAY set to point to it:

```
DISPLAY=:0 swipl

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 1, 2023, 10:36am UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/2 "2023-12-01T10:36:39Z")

</div>

Ideally, the formulas get updated. Having the GUI there by default seems ideal. As a variant is better than not at all. Any Homebrew users who can get this arranged?

---

<div class="post-metadata">

**Author:** ![MikeNZ](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@MikeNZ](https://swi-prolog.discourse.group/u/MikeNZ)\
**Post date:** [April 30, 2024, 9:19am UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/3 "2024-04-30T09:19:57Z")

</div>

I tried following the instructions very carefully. But all that happens is that it runs swipl in the little xterm window.

I am trying to get swipl running with the xpce like I had on my old Mac. On my new Mac all I seem to be able to do is run swipl in a term window.

Or I download the binary, but that doesn’t have “file” or “edit” drop down menus like on my old Mac.

Is there anyway to fix this? What am I doing wrong.

Thanks.

Mike

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 30, 2024, 9:47am UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/4 "2024-04-30T09:47:48Z")

</div>

Which versions, what MacOS version? Did you download the `.dmg` file from [www.swi-prolog.org](http://www.swi-prolog.org)? Opening SWI-Prolog, either from the .dmg or after installing should open a window with a menu, even if Xquartz is not installed. With Xquartz installed, the built-in editor should work.

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [April 30, 2024, 7:16pm UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/5 "2024-04-30T19:16:39Z")

</div>

I am a Homebrew user and compiles swi-prolog from source via GIT.  
I have made a test to install SWI-Prolog exactly following your recipe,  
and surprisingly for me, who usually easily fails to follow such instruction,  
it is successful with the following `brutal` final step:

```prolog
% brew link --overwrite swi-prolog          
Linking /usr/local/Cellar/swi-prolog/9.2.4... 7 symlinks created.
% 

```

As far as I have tested, the installed swipl program with homebrew seems equivalent  
in any aspects to the one via GIT.

Thanks for giving chance to see a formula of swi-prolog of homebrew, though  
I have reinstalled the GIT version without trouble.

---

<div class="post-metadata">

**Author:** ![MikeNZ](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@MikeNZ](https://swi-prolog.discourse.group/u/MikeNZ)\
**Post date:** [April 30, 2024, 8:45pm UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/6 "2024-04-30T20:45:41Z")

</div>

I tried it both ways. I used the .dmg and got something that looks like the old swi-prolog, but it doesn’t have any menu buttons like “file” or “edit” or “run”. It only has a “swi-prolog” menu which has nothing in it but “hide swi-prolog”, “hide others”.

Then I tried building it in home-brew which just runs it in a xterm window (same as running in terminal).

I am running Mac OS Sonoma on an Apple M3 Max. I use to use the “file” “edit” and “run” buttons a lot so this will be a big switch for me if I can’t get them back.

Thanks for all the help.

---

<div class="post-metadata">

**Author:** ![MikeNZ](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@MikeNZ](https://swi-prolog.discourse.group/u/MikeNZ)\
**Post date:** [April 30, 2024, 10:24pm UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/7 "2024-04-30T22:24:41Z")

</div>

To be precise, this is what it looks like when I use the .dmg file.

 ![IMG_3634](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/6/652abb49ae89f0fe6bf84c94825a57363289f03e.jpeg)  
 ![IMG_3635](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/8/839630eb735a2e95ae399ca32dbbec1e468da54d.jpeg)

This is the .dmg that I downloaded:  
[SWI-Prolog **9.2.4-1** for MacOSX 10.14 (Mojave) and later on x86\_64 and arm64](https://www.swi-prolog.org/download/stable/bin/swipl-9.2.4-1.fat.dmg)

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [April 30, 2024, 11:40pm UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/8 "2024-04-30T23:40:13Z")

</div>

Looks much better than swi-prolog which I installed via homebrew. I thought if I were familiar  
with X-window configuration on macOS, I could have enjoyed such window version.  
In fact, in stead of learning toward such X-window version, I chosen gnu emacs and  
ediprolog mode, with which I should be satisfied, though fairly frequently on debugging swi-prolog codes the emacs goes crazy (neither C-c nor C-g acceptable).

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 1, 2024, 8:00am UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/9 "2024-05-01T08:00:50Z")

</div>

> [@MikeNZ](#):
>
> To be precise, this is what it looks like when I use the .dmg file.

That is not good. I have little clue what is wrong. Works fine for me on Mac OS Sonoma, be it on a Macbook air with M1. Anyone else having trouble? Note that this has nothing to do with xpce. The console you see has been created by @CapelliC using Qt. Some of the menu operations, like **Edit** do use xpce. Showing the console itself is unrelated though.

I have little clue. Could be some environment variable that is blocking things? Notably look for `SWI` related variables or `DYLD` related stuff. I’d try to open the app from a terminal window using `open` or go into the app and run `swipl-win`. Possibly that shows a hint. Another option might be that there is something wrong in your `~/.config/swi-prolog/init.pl` (ok if it does not exist).

> [@kuniaki.mukai](#):
>
> Looks much better than [swi-prolog](https://www.swi-prolog.org/pldoc/doc_for?object=manual) which I installed via homebrew

You can get the same thing if you install Qt. It is a bit complicated process though. Might be easy if Homebrew supports Qt.

---

<div class="post-metadata">

**Author:** ![MikeNZ](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@MikeNZ](https://swi-prolog.discourse.group/u/MikeNZ)\
**Post date:** [May 1, 2024, 8:20am UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/10 "2024-05-01T08:20:30Z")

</div>

There is no ~/.config/swi-prolog/init.pl

If I run “open SWI-Prolog.app” from terminal I get the same behavior.

I thought it might be some Mac Privacy Settings, but nothing I do there seems to help.

I did install SWI-prolog twice (once from binary and once from homebrew).  
But it was broken before that:

Here is the printenv (is something important missing)?

\_\_CFBundleIdentifier=com.apple.Terminal  
TMPDIR=/var/folders/rc/pqtb7zms7bd\_4jqwx1yckmrm0000gn/T/  
XPC\_FLAGS=0x0  
TERM=xterm-256color  
SSH\_AUTH\_SOCK=/private/tmp/com.apple.launchd.VeH0kipgYq/Listeners  
XPC\_SERVICE\_NAME=0  
TERM\_PROGRAM=Apple\_Terminal  
TERM\_PROGRAM\_VERSION=453  
TERM\_SESSION\_ID=968AF0DA-71BC-4418-883F-8578109624BC  
SHELL=/bin/zsh  
HOME=/Users/mikebarley  
LOGNAME=mikebarley  
USER=mikebarley  
PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin  
SHLVL=1  
PWD=/Users/mikebarley/.config/swi-prolog  
OLDPWD=/Users/mikebarley/.config  
HOMEBREW\_PREFIX=/opt/homebrew  
HOMEBREW\_CELLAR=/opt/homebrew/Cellar  
HOMEBREW\_REPOSITORY=/opt/homebrew  
MANPATH=/opt/homebrew/share/man::  
INFOPATH=/opt/homebrew/share/info:  
HOMEBREW\_NO\_INSTALL\_FROM\_API=1  
EDITOR=/usr/bin/nano  
LANG=en\_NZ.UTF-8  
\_=/usr/bin/printenv  
mikebarley@Mikes-MacBook-Pro swi-prolog %

Thanks for all the help!

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 1, 2024, 8:51am UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/11 "2024-05-01T08:51:26Z")

</div>

Environment looks clean.

> [@MikeNZ](#):
>
> If I run “open [SWI-Prolog](https://www.swi-prolog.org/pldoc/doc_for?object=manual).app” from terminal I get the same behavior.

Does it print any messages to the terminal where you run `open`?

As you have a Prolog prompt, is there anything suspicious if you run

```
?- check_installation.

```

By default it should complain about JPL and `swipl-win` not being in `PATH`.

Another thing to try is to run

```
?- init_win_menus.

```

This should normally be executed at startup time. If it works when called later we may be facing some timing issue. If it still does not add menus you can trace through it and see whether you can find what is wrong.

---

<div class="post-metadata">

**Author:** ![MikeNZ](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@MikeNZ](https://swi-prolog.discourse.group/u/MikeNZ)\
**Post date:** [May 1, 2024, 9:06am UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/12 "2024-05-01T09:06:26Z")

</div>

check\_installation looked OK.

But, init\_win\_menus fixed it!!!

As soon as I typed it in all the menus appear!!!

Thanks heaps and stacks!!

Mike

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 1, 2024, 9:39am UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/13 "2024-05-01T09:39:34Z")

</div>

> [@MikeNZ](#):
>
> But, init\_win\_menus fixed it!!!

Great. Possibly you can put that in `~/.config/swi-prolog/init.pl` with a short delay, e.g.

```
 :- initialization sleep(0.1), init_win_menus.

```

May or may not work … I’m afraid your M3 is too fast 🙂

@CapelliC, do you have any idea for a real fix?

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [May 12, 2024, 3:39pm UTC](https://swi-prolog.discourse.group/t/installing-swi-prolog-on-mac-os-x-with-xpce-support-via-homebrew/7016/14 "2024-05-12T15:39:18Z")

</div>

> [@kuniaki.mukai](#):
>
> In fact, in stead of learning toward such X-window version, I chosen gnu emacs and  
> ediprolog mode, with which I should be satisfied, though fairly frequently on debugging [swi-prolog](https://www.swi-prolog.org/pldoc/doc_for?object=manual) codes the emacs goes crazy (neither C-c nor C-g acceptable).

Recently I noticed that in such emergency situations, the following two Emacs functions  
almost always surely makes me avoid forcing to kill Emacs.app.

```prolog
( GNU Emacs 29.1 (build 1, x86_64-apple-darwin21.6.0, Carbon Version 165 AppKit 2113.6) of 2023-08-08)

```

```prolog
M-x kill-process (attched to the current buffer)
M-x ediprolog-toplevel

```
