R reticulate libstdc++so GLIBCXX_3.4.21 not found issue

Question:

I was trying to use pandas from R . I used the reticulate library for the same. The sample code I used is given below

library(reticulate)
use_condaenv("my_env_37",required=T)
py_discover_config()
py_run_string("import pandas as pd")

Error

> py_run_string("import pandas as pd")
Error in py_run_string_impl(code, local, convert) :
  ImportError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /opt/anaconda/envs/my_env_37/lib/python3.6/site-packages/pandas/_libs/window.cpython-36m-x86_64-linux-gnu.so)

Detailed traceback:
  File "<string>", line 1, in <module>
  File "/opt/anaconda/envs/my_env_37/lib/python3.6/site-packages/pandas/__init__.py", line 42, in <module>
    from pandas.core.api import *
  File "/opt/anaconda/envs/my_env_37/lib/python3.6/site-packages/pandas/core/api.py", line 26, in <module>
    from pandas.core.groupby import Grouper
  File "/opt/anaconda/envs/my_env_37/lib/python3.6/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
    from pandas.core.groupby.groupby import GroupBy  # noqa: F401
  File "/opt/anaconda/envs/my_env_37/lib/python3.6/site-packages/pandas/core/groupby/groupby.py", line 37, in <module>
    from pandas.core.frame import DataFrame
  File "/opt/anaconda/envs/my_env_37/lib/python3.6/si
Calls: py_run_string -> py_run_string_impl
Execution halted

Output from py_discover_config()


> py_discover_config()
python:         /opt/anaconda/envs/my_env_37/bin/python
libpython:      /opt/anaconda/envs/my_env_37/lib/libpython3.6m.so
pythonhome:     /opt/anaconda/envs/my_env_37:/opt/anaconda/envs/my_env_37
version:        3.6.8 |Anaconda custom (64-bit)| (default, Dec 30 2018, 01:22:34)  [GCC 7.3.0]
numpy:          /opt/anaconda/envs/my_env_37/lib/python3.6/site-packages/numpy
numpy_version:  1.16.2

NOTE: Python version was forced by use_python function

Conda version : 4.6.8
Python Version : 3.6.8
Pandas Version : 0.24.2
OS: RHEL 7.4
R Version : 3.5.1
reticulate Version : 1.9

Is there any other configuration we have to use for getting this working. When I run the same pandas import from Python alone it is working as expected.

Answers:

It seems that your GCC is too old to be used with your R module. This issue is not related to R but the error message is the same.

Do you have several installations of GCC (in particular in /usr/local)? If so, you can try something like export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/usr/local/lib64:/usr/lib64 as suggested in the previous link I gave.

Otherwise, you should install a newer version of GCC (in a module environment if you still need your current version of GCC, see here for details, the explanations are very clear IMHO). Then, you will need to run R with your new environment.

Answered By: ractiv

I ran into a similar issue in a GitHub Action, and this answer finally help me after many trials. Essentially, I added the following as a step in my .github/workflows/pythonapp.yml file:

conda install -c conda-forge libstdcxx-ng
sudo rm /usr/lib/x86_64-linux-gnu/libstdc++.so.6
sudo ln -s /home/runner/.local/share/r-miniconda/pkgs/libstdcxx-ng-12.1.0-ha89aaad_16/lib/libstdc++.so.6.0.30 /usr/lib/x86_64-linux-gnu/libstdc++.so.6

Explanation

My initial error was:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /home/runner/.local/share/r-miniconda/envs/r-reticulate/lib/python3.8/site-packages/scipy/optimize/_highs/_highs_wrapper.cpython-38-x86_64-linux-gnu.so)

so I needed to remove the existing libstdc++.so.6 and make a symlink for it in /usr/lib/x86_64-linux-gnu/.

find / -name "libstdc++.so*" showed me where my libstdc++.so.6.0.30 file was, so then the last step was to point the symlink there.

Answered By: trangdata
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.