Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reticulate not looking for shared libraries in conda env lib directory #1285

Open
carmensandoval opened this issue Oct 3, 2022 · 3 comments
Labels

Comments

@carmensandoval
Copy link

carmensandoval commented Oct 3, 2022

library(reticulate)
reticulate::use_condaenv("/path/to/conda/envs/pegasus",
                         conda = "/path/to/conda/condabin/conda",
                         required = TRUE)

python:         /path/to/conda/envs/pegasus/bin/python
libpython:      /path/to/conda/envs/pegasus/lib/libpython3.9.so
pythonhome:     /path/to/conda/envs/pegasus
version:        3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:56:21)  [GCC 10.3.0]
numpy:          /path/to/conda/envs/pegasus/lib/python3.9/site-packages/numpy
numpy_version:  1.23.3

NOTE: Python version was forced by RETICULATE_PYTHON
import pegasus as pg

ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /path/to/conda/envs/pegasus/lib/python3.9/site-packages/scipy/linalg/_matfuncs_sqrtm_triu.cpython-39-x86_64-linux-gnu.so)

The file where it's looking naturally does not have the requited GLIBXX version:

ls /usr/lib/x86_64-linux-gnu/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6 -> libstdc++.so.6.0.25

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep 

GLIBCXX_3.4
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25

But libstdc++.so.6.0.30 in /path/to/conda/env/ does have the required version:

ls -lha /path/to/conda/lib | grep libstdc

lrwxrwxrwx   1 2020911 1279   19 Jul  7 06:31 libstdc++.so -> libstdc++.so.6.0.30
lrwxrwxrwx   1 2020911 1279   19 Jul  7 06:31 libstdc++.so.6 -> libstdc++.so.6.0.30
-rwxrwxr-x+  4 2020911 1279  12M May 11 20:30 libstdc++.so.6.0.30
strings /path/to/conda/lib/libstdc++.so.6.0.30 | grep GLIBCXX_3.4

GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_3.4.29
GLIBCXX_3.4.30

Trying to add the conda env library directory (/path/to/conda/lib) to $LD_LIBRARY_PATH doesn't effect any change:

system("export LD_LIBRARY_PATH=/path/to/conda/lib:$LD_LIBRARY_PATH")
system("echo LD_LIBRARY_PATH") 

Returns an unchanged path, without including /path/to/conda/lib

How can I specify that it needs to look in /path/to/conda/env/lib/ for that GLIBCXX_3.4.26 library?

I can load import other modules from this same env without any issues.

@carmensandoval carmensandoval changed the title Reticulate not looking for lib/libstdc++.so in conda env directory Reticulate not looking for shared libraries in conda env directory Oct 3, 2022
@carmensandoval carmensandoval changed the title Reticulate not looking for shared libraries in conda env directory Reticulate not looking for shared libraries in conda env lib directory Oct 3, 2022
@jan-glx
Copy link

jan-glx commented Oct 4, 2022

My understanding is that you cannot do stuff like that (i.e. almost anything slightly advanced) in general with reticulate as the reticulate python runs in the same process as R and thus are bound to have the same environment. If there requirements for the environment are conflicting there is nothing you can do.

One (painful) solution is t use R from within your conda environment (installing it there).

Another, probably better, solution is to use python in a separate process with basilisk (which, i believe, combines calleR with reticulate to achieve that) .

@kevinushey
Copy link
Collaborator

In some cases you can, but you need to set your LD_LIBRARY_PATH before R is launched so that Conda libraries are preferred to the default system libraries.

Or just use a virtual environment...

@davidzgli
Copy link

If you do not mind running R standalone, for example, starting R session in a terminal, reticulate package does honor the GLIBCXX in a conda envrionment. Here is the procedure that works for me.

  1. Create a cond env
  2. Install appropriate version of gcc and g++ in the environment
    conda install -c conda-forge gcc
    conda install -c conda-forge gxx
  3. Export LD_LIBRARY_PATH environment variable in a terminal.
    export LD_LIBRARY_PATH=/paths/envs/env_name/lib:$LD_LIBRARY_PATH
  4. Start R in this terminal
  5. Check LD_LIBRARY_PATH via the command Sys.getenv("LD_LIBRARY_PATH")

One nasty way to make reticulate honors conda env in Rstudio server is to modify R system file ldpaths , i.e., put export LD_LIBRARY_PATH=/paths/envs/env_name/lib:$LD_LIBRARY_PATH at the bottom of a file like /opt/R/4.3.2/lib/R/etc/ldpaths on CentOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants