Hi all,
I’m trying to install swipl in a conda environment so that it uses the python executable and packages from the environment.
No luck yet.
I tried the suggestions here https://www.swi-prolog.org/pldoc/man?section=janus-venv
and I tried configuring with
When I look at CMakeCache.txt it seems it has correctly picked up the environment:
//Path to a program.
PROG_PYTHON:FILEPATH=/hpc/home/rzf/.conda/envs/pytorch/bin/python3
//Path to a program.
PROTOC:FILEPATH=PROTOC-NOTFOUND
//No help, variable specified on the command line.
Python_ROOT_DIR:UNINITIALIZED=~/.conda/envs/pytorch/bin
but when I run swipl I get:
(pytorch) [rzf@hnode01 nations]$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.11-8-gfb487feae)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- py_version.
% Interactive session; added `.` to Python `sys.path`
% Janus 1.4.0 embeds Python 3.9.16 (main, Dec 8 2022, 00:00:00)
[GCC 11.3.1 20221121 (Red Hat 11.3.1-4)]
true.
while
(pytorch) [rzf@hnode01 nations]$ python
Python 3.9.19 | packaged by conda-forge | (main, Mar 20 2024, 12:50:21)
[GCC 12.3.0] on linux
Note that Python and the embedding library are for most Linux distros distinct packages. I do not know about conan.
But then, I do not know (doubt it) that it will set RUNPATH (or RPATH) of the Janus interface. It surely does not when using the above standard location. Doesn’t conan set LD_LIBRARY_PATH?
I made another experiment by using a different major version of Python for the conda environment, so that the difference between the two environments is clearer. I have Python 3.9 outside conda and 3.11 in the conda environment torch.
Now I see in CMakeCache.txt:
//Details about finding Python
FIND_PACKAGE_MESSAGE_DETAILS_Python:INTERNAL=[/hpc/home/rzf/.conda/envs/torch/bin/python3][/hpc/home/rzf/.conda/envs/torch/include/python3.11][/hpc/home/rzf/.conda/envs/torch/lib/libpython3.11.so][cfound components: Interpreter Development Development.Module Development.Embed ][v3.11.10(3.6)]
So the installation has correctly got the Python library.
However, swipl cannot find it
(torch) [rzf@hnode01 buildconda4]$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.11-8-gfb487feae)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- py_version.
ERROR: /hpc/home/rzf/lib/swipl/library/ext/swipy/janus.pl:116:
ERROR: /hpc/home/rzf/lib/swipl/library/ext/swipy/janus.pl:116: Initialization goal raised exception:
ERROR: libpython3.11.so.1.0: cannot open shared object file: No such file or directory
ERROR: In:
ERROR: [55] throw(error(shared_object(open,'libpython3.11.so.1.0: cannot open shared object file: No such file or directory'),context(...,_664)))
ERROR: [53] <meta call>
ERROR: [52] with_mutex('$foreign',load_foreign_library(foreign(janus),janus,[...])) <foreign>
ERROR: [50] '$run_init_goal'(shlib:load_foreign_library(...,...)) at /hpc/home/rzf/lib/swipl/boot/init.pl:826
ERROR: [49] catch(system:'$run_init_goal'(...),_806,system:'$initialization_error'(_828,...,...)) at /hpc/home/rzf/lib/swipl/boot/init.pl:565
ERROR: [48] catch_with_backtrace(system:'$run_init_goal'(...),_864,system:'$initialization_error'(_886,...,...)) at /hpc/home/rzf/lib/swipl/boot/init.pl:645
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
ERROR: Exported procedure janus:py_is_object/1 is not defined
ERROR: Exported procedure janus:py_iter/2 is not defined
ERROR: Exported procedure janus:py_gil_owner/1 is not defined
ERROR: Exported procedure janus:py_free/1 is not defined
ERROR: Exported procedure janus:py_call/3 is not defined
ERROR: Exported procedure janus:py_with_gil/1 is not defined
ERROR: Exported procedure janus:py_setattr/3 is not defined
ERROR: Exported procedure janus:py_call/1 is not defined
ERROR: Exported procedure janus:py_iter/3 is not defined
ERROR: Exported procedure janus:py_call/2 is not defined
ERROR: [Thread 1]: exception handler failed to define janus:py_call/2
ERROR: Unknown procedure: janus:py_call/2
ERROR: However, there are definitions for:
ERROR: janus:px_call/4
ERROR: janus:py_call/4
ERROR:
ERROR: In:
ERROR: [13] janus:py_call(sys:version,_13856)
ERROR: [12] janus:py_version at /hpc/home/rzf/lib/swipl/library/ext/swipy/janus.pl:161
ERROR: [11] toplevel_call(user:user:py_version) at /hpc/home/rzf/lib/swipl/boot/toplevel.pl:1318
Exception: (13) janus:py_call(sys:version, _12136) ? creep
?-
% halt
(torch) [rzf@hnode01 buildconda4]$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.11-8-gfb487feae)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- py_version.
% Interactive session; added `.` to Python `sys.path`
% Janus 1.4.0 embeds Python 3.11.10 | packaged by conda-forge | (main, Sep 10 2024, 11:19:15) [GCC 13.3.0]
true.
?-
I’ve had similar problems when other libraries weren’t in the default location. So, a generic way of adding libraries (rpath? LIBRARY_PATH?) to the executable could be good. (I think I first ran into this when I built gcc in ~/.local)
It can only be a cmake option. At runtime you have LD_LIBRARY_PATH and various tools to edit the runtime path of binaries. But, this is all very platform specific
I’d first have to check what cmake offers out of the box. I know it has several options to control RUNPATH on ELF systems.
Hi. Sorry to re-open this discussion but would you mind giving me a bit more background on what the status is for swi + janus in conda?
I have the following issue: I am on a fairly locked down version of RH 8, so the only way for me to install swi is via conda (the RHEL packages are all 8.X). The conda forge feedstock is currently stuck on 9.0.4. I am also trying to install Janus from pip but it gives me an error that it requires 9.1.2 or newer.
Is there any chance there may be a combined swi + janus package on conda in the near-ish future? If not, I’d welcome any other suggestions!
The conda route still need a not of work to get mature. Whether or not that will happen is an open issue. It depends on people willing to invest.
What is wrong installing SWI-Prolog from source? Provided RH8’s gcc supports C11, this should be fairly easy. The dependencies are at SWI-Prolog on Redhat (Fedora, RHEL, CentOS). On most systems the process is pertty straightforward.