使用pyswip(mac)时出现错误libpl (shared) not found.
(详见下文)。我知道几年前有一个关于它的问题,但它没有解决。我用自制软件安装swiprolog(> 7.0.0)并为pyswip运行2to3。帮助我。
PS:我正在学习逻辑编程,我需要它。
找不到libpl(共享)。可能的原因:1)SWI-Prolog没有 安装为共享库。安装SWI-Prolog(5.6.34只是工作 罚款)发生异常,使用%tb查看完整的回溯。
此处抛出错误。
# UNIX-like
try:
_lib = CDLL("libpl.dylib")
except IndexError:
# let's try the cwd
_lib = CDLL("./libpl.so")
答案 0 :(得分:1)
我终于找到了解决方案:pyswip不支持SWI-Prolog 8.x.x,唯一对我有用的SWI-Prolog版本是Homebrew的swi-prolog 7.6.4(最新的7.x.x稳定发行版)。由于Homebrew无法跟踪swi-prolog的不同版本,因此我不得不认真研究以找到旧的7.6.4“公式”。现在,它可以与当前版本的pyswip(0.2.8)一起使用。
TL; DR:删除当前的SWI-Prolog安装(并删除所有相关的PATH编辑),执行brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/09a94009142a6265b0b8e322463100610aeda964/Formula/swi-prolog.rb
并开始。
编辑:
注意:这种方法不允许您使用某些Prolog软件包,例如library(process)
和library(http/json)
。要解决此问题,您可以安装macOS应用,然后手动安装并重新链接libncurses.6.dylib
,以便PySwip能够找到它,如下所示:
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