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

ImportError: `GLIBCXX_3.4.30' not found #1282

Closed
rvanlaar opened this issue Sep 22, 2022 · 9 comments
Closed

ImportError: `GLIBCXX_3.4.30' not found #1282

rvanlaar opened this issue Sep 22, 2022 · 9 comments
Labels

Comments

@rvanlaar
Copy link

rvanlaar commented Sep 22, 2022

Running

import scipy.stats as stats

gives the following error:

ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /home/handboek/.local/share/r-miniconda/envs/r-reticulate/lib/python3.8/site-packages/scipy/optimize/_highs/_highs_wrapper.cpython-38-x86_64-linux-gnu.so)

It might be a path issue. The created miniconda enviroment by reticulate is sound.
And the included libstdc++.so.6 in the miniconda enviroment does contain the GLIBCXX_3_4.30 string.

/home/handboek/.local/share/r-miniconda/envs/r-reticulate/bin/python
Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:18) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy.stats as stats
>>> 

reproduction:

> library("reticulate")
> install_miniconda()
< snip>
> py_discover_config()
python:         /home/handboek/.local/share/r-miniconda/envs/r-reticulate/bin/python
libpython:      /home/handboek/.local/share/r-miniconda/envs/r-reticulate/lib/libpython3.8.so
pythonhome:     /home/handboek/.local/share/r-miniconda/envs/r-reticulate:/home/handboek/.local/share/r-miniconda/envs/r-reticulate
version:        3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:18)  [GCC 10.3.0]
numpy:          /home/handboek/.local/share/r-miniconda/envs/r-reticulate/lib/python3.8/site-packages/numpy
numpy_version:  1.23.3
> pad <- py_discover_config()
> use_python(pad$python)
> py_install("scipy")
+ '/home/handboek/.local/share/r-miniconda/bin/conda' 'install' '--yes' '--prefix' '/home/handboek/.local/share/r-miniconda/envs/r-reticulate' '-c' 'conda-forge' 'scipy'
Collecting package metadata (current_repodata.json): done
Solving environment: done
<snip>
Downloading and Extracting Packages
scipy-1.9.1          | 26.2 MB   | ################################################## | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Retrieving notices: ...working... done
> repl_python()
Python 3.8.13 (/home/handboek/.local/share/r-miniconda/envs/r-reticulate/bin/python)
Reticulate 1.26 REPL -- A Python interpreter in R.
Enter 'exit' or 'quit' to exit the REPL and return to R.
>>> import scipy.stats as stats
ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /home/handboek/.local/share/r-miniconda/envs/r-reticulate/lib/python3.8/site-packages/scipy/optimize/_highs/_highs_wrapper.cpython-38-x86_64-linux-gnu.so)
>>> exit

environment

> utils::sessionInfo() 
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 11 (bullseye)

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reticulate_1.26

loaded via a namespace (and not attached):
 [1] compiler_4.2.1  here_1.0.1      Matrix_1.5-1    rprojroot_2.0.3
 [5] rappdirs_0.3.3  Rcpp_1.0.9      grid_4.2.1      jsonlite_1.8.0 
 [9] png_0.1-7       lattice_0.20-45
> reticulate::py_config() 
python:         /home/handboek/.local/share/r-miniconda/envs/r-reticulate/bin/python
libpython:      /home/handboek/.local/share/r-miniconda/envs/r-reticulate/lib/libpython3.8.so
pythonhome:     /home/handboek/.local/share/r-miniconda/envs/r-reticulate:/home/handboek/.local/share/r-miniconda/envs/r-reticulate
version:        3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:18)  [GCC 10.3.0]
numpy:          /home/handboek/.local/share/r-miniconda/envs/r-reticulate/lib/python3.8/site-packages/numpy
numpy_version:  1.23.3
sys:            [builtin module]

NOTE: Python version was forced by use_python function
@yoshidk6
Copy link

yoshidk6 commented Oct 9, 2022

I ran into a similar situation when I was trying to import xgboost in R with reticulate, while xgboost import was perfectly fine in Python REPL.
The solution that worked for me was downgrading xgboost from 1.6.x (which requires GLIBCXX_3.4.30) to 1.5.x.

TL;DR

The problem seems to be stemming from different libstdc++.so.6 being called between R (& reticulate) and Conda/Python. (Note for those who are not familiar including myself: this post (https://unix.stackexchange.com/a/557929) had nice explanations on what exactly are libstdc++.so.6, GLIBCXX_*, ...)

In your case /usr/lib/x86_64-linux-gnu/libstdc++.so.6, which I assume is the system default, is used by R & reticulate.
If you run strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX, you will see up to which version of GLIBCXX your libstdc++.so.6 supports.
In my case it was up to GLIBCXX_3.4.28 and did not include GLIBCXX_3.4.30. This was the cause of the issue.

As far as I can see, there are couple of potential solutions. Only the last one worked for me.

  1. Upgrade your system default libstd (libstdc++.so.6: version `GLIBCXX_3.4.22' not found  lhelontra/tensorflow-on-arm#13 (comment)). I didn't have sudo access
  2. Set LD_LIBRARY_PATH to tell R which exact library to use. This might not work according to this comment (`GLIBCXX_3.4.21' not found #841 (comment))
  3. Replace the system default libstdc++.so.6 with symbolic link to a newer version of libstdc++.so.6 somewhere in your system, like the one in conda (`GLIBCXX_3.4.21' not found #841 (comment)). Again I didn't have sudo access
  4. Use an older version of Python packages that depends only on an older version of GLIBCXX

It would be super nice if reticulate package can detect this kind of incompatibility and flag this in a warning message.

@MKhGenesis
Copy link

https://stackoverflow.com/questions/73317676/importerror-usr-lib-aarch64-linux-gnu-libstdc-so-6-version-glibcxx-3-4-30
try this one

@ArnoZWang
Copy link

https://stackoverflow.com/questions/58424974/anaconda-importerror-usr-lib64-libstdc-so-6-version-glibcxx-3-4-21-not-fo
Have you ever tried this solution? It worked fine for me.

@HeyWeCome
Copy link

执行这个命令就可以了:

conda install -c conda-forge gcc=12.1.0

@t-kalinowski
Copy link
Member

This is due to a binary incompatibility between conda and the R installation.

The most straightforward solution is to switch from conda to virtual environments, which don't suffer from the same problem.

library(reticulate)
install_python("3.10:latest")
virtualenv_create("r-scipy", version = "3.10", packages = "scipy")

(( The less straightforward solution is to have conda provide the R binary and all R packages. Note that this approach means that you can't use pre-built packages from CRAN or RStudio builds provided by Posit. ))

barrettk added a commit to barrettk/pythonR that referenced this issue Nov 9, 2023
 - add support for importing modules from various locations
 - R CMD Check and tests are passing
 - Note: Metworx does not support "pandas" via a conda environment. It seems to stem from different libstdc++.so.6 versions being called between R and conda/python. A virtual environment may not have this issue, but using the pre-set path to python avoids this issue within conda environments. See more details here: rstudio/reticulate#1282
@mailmrcai
Copy link

this command is ok: conda install -c conda-forge gcc=12.1.0

@avishai987
Copy link

I also recommend to switch to virtual env, that's the only solution that solved the 'GLIBCXX_3.4.30' not found error
(I also don't have sudo premission).

library(reticulate)
virtualenv_create("<your_path>/cnmf_dev", packages = <your_packages>,required = T)
use_virtualenv("<your_path>/cnmf_dev",required = T)

@LukeLIN-web
Copy link

LukeLIN-web commented Apr 9, 2024

this command is ok: conda install -c conda-forge gcc=12.1.0

Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.

I tried export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: $HOME/miniconda3/lib/ it also failed.

Finally, I find the solution
pybind/pybind11#3453 (comment)

It can works.

@lumbric
Copy link

lumbric commented Apr 29, 2024

This issue is not specific to reticulate. I've written a comprehensive overview on stackoverflow explaining what is happening here and possible ways to fix it.

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

10 participants