使用pyswip(mac)时有关libpl(shared)的错误

2024-09-26 22:07:36 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用pyswip(mac)时,我得到了一个错误libpl (shared) not found.(请参阅下面的详细信息)。我知道几年前有一个关于它的问题,但它没有得到解决。我用自制软件安装了swiplog(>;7.0.0),并为pyswip运行2to3。帮助我。在

PS:我在学习逻辑编程,我需要它。在

libpl (shared) not found. Possible reasons: 1) SWI-Prolog not installed as a shared library. Install SWI-Prolog (5.6.34 works just fine) An exception has occurred, use %tb to see the full traceback.

错误在这里抛出。在

# UNIX-like
try:
    _lib = CDLL("libpl.dylib")
except IndexError:
    # let's try the cwd
    _lib = CDLL("./libpl.so")

Tags: themaclib错误not请参阅详细信息prolog
1条回答
网友
1楼 · 发布于 2024-09-26 22:07:36

我终于找到了一个解决方案:pyswip不支持SWI-Prolog 8.x.x,唯一适合我的SWI-Prolog版本是自制的SWI-Prolog 7.6.4(最新的7.x.x稳定版本)。因为自制程序不能跟踪不同版本的swi-prolog,所以我不得不去挖掘旧的7.6.4“公式”。现在它可以与当前版本的pyswip(0.2.8)一起工作。在

TL;DR:删除当前的SWI-Prolog安装(并删除任何相关的路径编辑),然后执行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

相关问题 更多 >

    热门问题