pyswip
pyswip copied to clipboard
Cant import
I got a problem when using ‘pyswip'. Maybe the function re.search miss an argument(‘swi_ver’) ? Is it necessary to input the version of swi-prolog? It never happened to me before.
same problem. it must be a bug. just add swi_ver into re.serearch
Same problem. The code here makes no sense because re.search(regex_pattern, string_to_search)
takes two arguments but on line 310 here there is only the pattern
argument, so of course the code raises: https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L306-L314
Another critical error in code is that the walk
function has inconsistent return types. Although walk
's docstring specifies a str
return, the _findSwiplMacOSHome
function expects a (res_path, back_path)
return from walk
. The walk
function can even return a None: https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L274-L303
Here's the referenced _findSwiplMacOSHome
function which expects walk
to return a (str, str)
return. https://github.com/yuce/pyswip/blob/f7c1f1e8c3a13b90bd775861d374788a8b5677d8/pyswip/core.py#L317-L355
@yuce After some digging, I think a deeper problem is that pyswip
doesn't support SWI-Prolog 8.x, because the version-seeking functions in pyswip/core.py
look for libswipl.xx
and libpl.xx
but those no longer exist starting with swipl 8.0.1. See the official list of all stable releases.
I finally found a solution: the only SWI-Prolog version that has worked for me is Homebrew's swi-prolog
7.6.4 (latest 7.x.x stable release). Because Homebrew does not keep track of different versions of swi-prolog
, I had to really dig to find the old 7.6.4 "formula". Now it works with the current version of pyswip (0.2.8).
So remove your current SWI-Prolog install (and remove any associated PATH editing) and brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/09a94009142a6265b0b8e322463100610aeda964/Formula/swi-prolog.rb
and call it a day.
Caveat: This approach will not let you use some of the packages, such as library(process)
or library(http/json)
. To do this, you can still install the macOS app, but you have to manually install and relink the libncurses.6.dylib
in order for PySwip to be able to find it, like this:
brew install ncurses # Specifically install this library
sudo find / -name "libncurses.6.dylib" # You'll see an entry in /usr/local/Cellar/ncurses/6.1/lib/libncurses.6.dylib or something like that in /.../Cellar/ncurses/ (Homebrew folder)
# Now go relink the libswipl.dylib to depend on the newly installed `ncurses` library
cd /Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin15.6.0 # The "darwin" version may vary depending on your OS/SWI-Prolog version
# You'll see that it is linked against a fake /opt/local/lib/libncurses.6.dylib which doesn't in fact exist
otool -L libncurses.6.dylib
# Now check the top-level lib, libswipl.dylib, it should show a "@executable_path/../swipl/lib/x86_64-darwin15.6.0/libncurses.6.dylib" or something like that depending on your version.
otool -L libswipl.dylib
# Now replace the fake with the real by actually modifying the top-level lib, libswipl.dylib. Contrary to intuition, the way linking works in macOS is that you can only modify the depending library, so libswipl.dylib instead of libncurses.6.dylib.
install_name_tool -change @executable_path/../swipl/lib/x86_64-darwin15.6.0/libncurses.6.dylib /usr/local/Cellar/ncurses/6.1/lib/libncurses.6.dylib libswipl.dylib
# Now you'll see that libswipl.dylib has been successfully modified:
otool -L libswipl.dylib
@zhanwenchen Thank you. This helped me.
hello, any chance that we can see this bug fixed?
Good point @andreaBelmont. I am happy to help as well.
I tried to hack this file on mac for latest swi 8.0.3 but after 1 hour I decided I didnt want to get into this
could someone fix this so us mac people can get back to work??
thanks
DS