# Janus and Conda

**URL:** <https://swi-prolog.discourse.group/t/janus-and-conda/7775>\
**Category:** Installing\
**Tags:** janus, python\
**Created:** [September 11, 2024, 12:07pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775 "2024-09-11T12:07:59Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![friguzzi](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/friguzzi/32/7045_2.png) [@friguzzi](https://swi-prolog.discourse.group/u/friguzzi)\
**Post date:** [September 11, 2024, 12:07pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/1 "2024-09-11T12:07:59Z")

</div>

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](https://www.swi-prolog.org/pldoc/man?section=janus-venv)  
and I tried configuring with

```prolog
cmake -DCMAKE_INSTALL_PREFIX=$HOME -DINSTALL_DOCUMENTATION=OFF -DPython_ROOT_DIR=~/.conda/envs/pytorch/bin -G Ninja ..

```

and with

```prolog
cmake -DCMAKE_INSTALL_PREFIX=$HOME -DINSTALL_DOCUMENTATION=OFF -DPython_FIND_VIRTUALENV=FIRST -G Ninja ..

```

When I look at `CMakeCache.txt` it seems it has correctly picked up the environment:

```prolog
//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:

```prolog
(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

```prolog
(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

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 11, 2024, 1:24pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/2 "2024-09-11T13:24:49Z")

</div>

What really matters is not where it finds python, but where it finds the library for an embedded Python system. E.g.

```prolog
> grep libpython CMakeCache.txt 
FIND_PACKAGE_MESSAGE_DETAILS_Python:INTERNAL=[/bin/python3.12][/usr/include/python3.12][/usr/lib64/libpython3.12.so][cfound components: Interpreter Development Development.Module Development.Embed][v3.12.5(3.6)]
_Python_LIBRARY_RELEASE:INTERNAL=/usr/lib64/libpython3.12.so

```

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`?

---

<div class="post-metadata">

**Author:** ![friguzzi](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/friguzzi/32/7045_2.png) [@friguzzi](https://swi-prolog.discourse.group/u/friguzzi)\
**Post date:** [September 11, 2024, 2:22pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/3 "2024-09-11T14:22:37Z")

</div>

> [@jan](#):
>
> Doesn’t conan set `LD_LIBRARY_PATH`?

No, conda does not set it.

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`:

```prolog
//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

```prolog
(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

```

---

<div class="post-metadata">

**Author:** ![friguzzi](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/friguzzi/32/7045_2.png) [@friguzzi](https://swi-prolog.discourse.group/u/friguzzi)\
**Post date:** [September 11, 2024, 2:26pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/4 "2024-09-11T14:26:17Z")

</div>

If I use

```prolog
export LD_LIBRARY_PATH=/hpc/home/rzf/.conda/envs/torch/lib/

```

then it works

```prolog
(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.

?-

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 11, 2024, 3:51pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/5 "2024-09-11T15:51:11Z")

</div>

So, possibly we need an option to use RUNPATH on janus.so if the Python lib is not in a default location? At least, you have a work-around 🙂

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [September 11, 2024, 4:25pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/6 "2024-09-11T16:25:52Z")

</div>

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`)

---

<div class="post-metadata">

**Author:** ![friguzzi](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/friguzzi/32/7045_2.png) [@friguzzi](https://swi-prolog.discourse.group/u/friguzzi)\
**Post date:** [September 11, 2024, 5:35pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/7 "2024-09-11T17:35:16Z")

</div>

> [@jan](#):
>
> So, possibly we need an option to use RUNPATH on janus.so if the Python lib is not in a default location? At least, you have a work-around 🙂

Should it be an installation option or a runtime option?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 11, 2024, 5:57pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/8 "2024-09-11T17:57:12Z")

</div>

> [@friguzzi](#):
>
> Should it be an installation option or a runtime option?

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.

---

<div class="post-metadata">

**Author:** ![friguzzi](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/friguzzi/32/7045_2.png) [@friguzzi](https://swi-prolog.discourse.group/u/friguzzi)\
**Post date:** [March 21, 2025, 1:08pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/9 "2025-03-21T13:08:28Z")

</div>

I think the correct option is `-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE`  
See [CMAKE\_INSTALL\_RPATH\_USE\_LINK\_PATH — CMake 4.0.0-rc4 Documentation](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH.html#variable:CMAKE_INSTALL_RPATH_USE_LINK_PATH)

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [March 21, 2025, 1:34pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/10 "2025-03-21T13:34:00Z")

</div>

Good. Lost track a little, but if it is something that needs to be done on SWI-Prolog please make a PR.

---

<div class="post-metadata">

**Author:** ![friguzzi](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/friguzzi/32/7045_2.png) [@friguzzi](https://swi-prolog.discourse.group/u/friguzzi)\
**Post date:** [March 21, 2025, 2:29pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/11 "2025-03-21T14:29:10Z")

</div>

Made a PR to include installation instructions in `CMAKE.md`

---

<div class="post-metadata">

**Author:** ![TomP](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@TomP](https://swi-prolog.discourse.group/u/TomP)\
**Post date:** [June 1, 2025, 4:25am UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/12 "2025-06-01T04:25:29Z")

</div>

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!

Thanks!

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [June 1, 2025, 5:31pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/13 "2025-06-01T17:31:37Z")

</div>

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)](https://www.swi-prolog.org/build/Redhat.md). On most systems the process is pertty straightforward.

---

<div class="post-metadata">

**Author:** ![TomP](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@TomP](https://swi-prolog.discourse.group/u/TomP)\
**Post date:** [June 3, 2025, 1:41pm UTC](https://swi-prolog.discourse.group/t/janus-and-conda/7775/14 "2025-06-03T13:41:30Z")

</div>

Hi Jan, thanks for the response! Understood, building from source was my next step.
