The pyswip package worked with the previous stable version of SWI Prolog (8.4.3), so I wonder if there’s a quick fix of downgrading to this SWI Prolog version.
If you are using the Ubuntu package manager for this you should probably search their docs for downgrading. I don’t know for certain but most package managers have some process to do exactly that. Maybe you have the previous package downloaded and need to downgrade? or maybe you need to install a specific version?
If I recall correctly, the problem with pyswip is that it hard-codes the C types and constants from SWI-Prolog.h in the Python code. But, running git diff -b V8.4.3 SWI-Prolog.h says nothing changed between 8.4.3 and 9.0.0, only some new stuff was added. So I wonder why pyswip is broken? Is it looking for libswipl.so.8?
What I can see, pyswip (in core.py) is looking for ‘libswipl.so’ and ‘libpl.so’, so the specific SWI Prolog version is not hard coded.
Regarding downgrading via PPA, do you know exactly what version name to use when specifying the version via apt-get? The syntax is apt-get install pkg=version but I don’t know the exact version name to use.
I was trying sudo apt install swi-prolog=swi-prolog_8.4.2 but it was not found.
I’m wondering what is wrong. The Prolog interface seems to load fine into Python using SWI-Prolog 9.0.0.
I did look at how pyswip loads libswipl. That can be improved. Following similar issues with sweep, there is now a flag libswipl that points at the shared object used by swipl (if any). I improved that a bit such that it is now fully reliable on Windows, MacOS and Linux (and other POSIX systems providing dladdr()) and make it available through swipl --dump-runtime-variables. I’ll make a PR on pyswip to use that as first choice.
But again, this does not seem to be the problem. That is to be expected as the installation locations have not changed and the interface should be fully binary compatible between 8.4.x and 9.0.x
I found that the community-maintained (universe) package sources needs to be enabled before instaling the package requirements to downgrade to the previous stable version of SWI Prolog (8.4.3) in Ubuntu 20.04 based docker images:
Depends how you installed it (download binary, Macports, Homebrew, built from source …) For the binary from the download page, download an older version and install it. Use the show all files at the bottom-right of the table to see all versions.
Of course, the question is “why?”. 9.x should be pretty compatible. So far only the pyswip issue came up, but that is fixed with a very simple edit in the pyswip package.
I think the challenge might be making that simple edit in the pyswip package available in our production continuous delivery pipelines. They are built around the Python Package Index at pypi.org and Personal Package Archives for Ubuntu at launchpad.net and companies feel confident integrating software from well-known sources.
I can imagine an ideal world where changes, including new versions in utilities like SWI-Prolog, trigger automated tests in dependency-using tools like PySwip so that the communities that support those tools can react faster to integration issues, merge the changes and release them through well known distribution channels.
I installed it through Homebrew. The problem I am faced with is that after reinstalling pyswip with your PR: #145 included, I am stilling getting the same error messages before the PR and after updating to 9.x. They are shown below:
File “/Users/amrsoliman/Documents/GitHub/mila/utils_modified.py”, line 15, in learn
prolog.consult(file_name)
File “/Users/amrsoliman/miniforge3/envs/M1/lib/python3.9/site-packages/pyswip/prolog.py”, line 168, in consult
next(cls.query(filename.join([“consult('”, “')”]), catcherrors=catcherrors))
File “/Users/amrsoliman/miniforge3/envs/M1/lib/python3.9/site-packages/pyswip/prolog.py”, line 128, in call
raise PrologError(“”.join([“Caused by: '”, query, "'. ",
pyswip.prolog.PrologError: Caused by: ‘consult(‘train.pl’)’. Returned: ‘error(instantiation_error, context(:(system, /(atom_chars, 2)), _3208))’.
And the simple quick fix is to find core.py in the package and replace PL_version with PL_version_info.
These may be unrelated to your problem though. It seems you can create an instance of Prolog. Without some context on what is supposed to happen I can’t comment on these errors (and anyway, my Python knowledge is not much).
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 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.
Do you know why the package swi-prolog-nox_8.4.3-1-g10c53c6e3-focalppa2_amd64.deb is not longer available in the usual URL ? Do you know an alternative way to get this package?