How to brew install swi-prolog 8.4.3 when 9.0.0 is out

I am having a lot of trouble installing the previous version of swi-prolog. For some reason, updating to 9.0.0 does not work with my codebase which uses pyswip. Could someone kindly help? =)

This might be relevant.

Best/easiest way to downgrade to version 8.4.3, on Linux Ubuntu 20.04

1 Like

Note that the homebrew package information is just a git repo. That means you can do anything git – in particular, reset back to a state in history. After that, when you uninstall the problematic package and then reinstall it, you’ll get the version that was latest at that point.

And in particular, there is GitHub - nobrowser/homebrew-personal: My personal Homebrew Tap which has just a very few packages alongside a “fixed” swi-prolog package, so if you time travel in that one you may not even need to come back :slight_smile: I just upgraded it to 9.0.0 yesterday.


Ian

1 Like

It finally works! The thread suggested by @EricGT was very useful. Here is how:

For some reason downloading SWI-Prolog 8.4.3 from the website is causing me another slew of errors. Therefore I went back to SWI-Prolog 9.x via homebrew.

By implementing D.Cox’s pyswip PR #133, I get the “Exception: swi-prolog version number could not be determined”.

Then I implemented @hakank 's suggestion by amending Cox’s “PL_version = _lib.PL_version” to “PL_version = _lib.PL_version_info”

Viola! Thankfully, it works! In case anyone is curious, I have been using Aleph.

Does anyone know if this works with Mac, I am trying to use Swi Prolog with Python for a project at university. I believe it doesn’t work with the current version 9. So I want to downgrade so I can use it

@Jacktopping56 When installing pyswip use this command in your venv:
pip install git+https://github.com/yuce/pyswip@master#egg=pyswip

This will install the latest version of pyswip that fixed the issue on Mac.

I seem to get the following errors, I am not sure what the issue is:
Traceback (most recent call last):
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/main.py”, line 3, in
from prolog_interface import load_rules
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/prolog_interface.py”, line 1, in
from pyswip import Prolog
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/venv/lib/python3.9/site-packages/pyswip/init.py”, line 29, in
from pyswip.prolog import Prolog
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/venv/lib/python3.9/site-packages/pyswip/prolog.py”, line 28, in
from pyswip.core import *
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/venv/lib/python3.9/site-packages/pyswip/core.py”, line 571, in
(_path, SWI_HOME_DIR) = _findSwipl()
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/venv/lib/python3.9/site-packages/pyswip/core.py”, line 420, in _findSwipl
(path, swiHome) = _findSwiplDar()
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/venv/lib/python3.9/site-packages/pyswip/core.py”, line 374, in _findSwiplDar
(path, swiHome) = _findSwiplFromExec()
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/venv/lib/python3.9/site-packages/pyswip/core.py”, line 93, in _findSwiplFromExec
rtvars = dict((name, value[1:-1]) for name, value in ret) # [1:-1] gets
File “/Users/jacktopping/Documents/University/Year 2/Semester 2/Logic Programming/Module Information & Assessment/Assessment/Project/stockAnalysis/venv/lib/python3.9/site-packages/pyswip/core.py”, line 93, in
rtvars = dict((name, value[1:-1]) for name, value in ret) # [1:-1] gets
ValueError: not enough values to unpack (expected 2, got 1)

@Jacktopping56 How did you install swi-prolog?

I’m not a Python user, but the stack locations hint that it is using some bundled version of pyswip?

I installed it via Homebrew, I then seem to get the error that it is not compatible with arm64 and that it needs x86_64

Have you tried opening swi-prolog in your terminal using the swipl command? This should determine whether it is swi-prolog or your python code. Homebrew should install it with no problems.

Yes, when I use the swipl command via terminal it works.
Someone has the same issue via Error when importing PySwip · Issue #76 · yuce/pyswip · GitHub, someone seems to have fixed this but I’m struggling to interpret what it is saying

If swipl is for x86_64 it will not work with arm64 Python in the same process (unlike some real magic happens :slight_smile: ) You can check the version using this:

?- current_prolog_flag(arch, X).
X = 'arm64-darwin'.

If Homebrew does not install for arm64, Macports does and the binaries from swi-prolog.org are “fat” binaries. Most likely there is also some trick to tell brew how to install for arm. Surely SWI-Prolog builds fine for arm and runs natively on Apple silicon. Actually pretty fast!

When I run that I also get X =‘arm64-darwin’.

When running where swipl in the terminal, I get /opt/homebrew/bin/swipl. It runs fine for me and I have a M1 Pro. Used the simple homebrew command as well.

I also get the same, I am also using a M1 pro.

Here is the code that I have been using, I don’t think this is the issue though