vinecopulib / pyvinecopulib

A Python library for vine copula models
MIT License
92 stars 21 forks source link

GLIBC_2.29 required when import pyvinecopulib #119

Closed singledoggy closed 6 months ago

singledoggy commented 7 months ago

I've noticed the #92 and #101, I also run codes in HPC and encountered this problem. I tried to compile install and manually git check to https://github.com/vinecopulib/vinecopulib/tree/258eb2d7758ce067ee7d53789067f0d3ebbb9375 like #115 mentioned. First, I need to point out that I need to use gcc-9.3.0 other than icc to compile, I don't know why but icc failed somehow. And after that, I get a different ImportError: GLIBCXX_3.4.30 not found I never learned anything about C++, so it's hard to find the problem. I'll back when I get more results.

tvatter commented 7 months ago

Regarding icc, the issue is that we never managed to compile vinecopulib with it. I've just looked into it and noticed that icc has been deprecated two years ago in favor of the Intel oneAPI DPC++/C++ Compiler. I will look into this again, as we've received this request a few times over the years.

Regarding glib, did you try updating the version as it seemed to have solved the problem in #92 ?

singledoggy commented 7 months ago

Thank you for your prompt response.

Thank you for letting me know that icc has been deprecated for two years. Since many of the legacy software in our field compile much faster with icc, I have set it as the default. In the future, I will check the compilation options. Perhaps it's worth mentioning in the documentation?

In fact, I do not have the authority to update the default GLIBC, which is too low-level and relied upon by many other applications. Furthermore, since the ImportError changes after I recompile, I think there might be a way to fix this error through some path linking methods or compilation parameters. As I am not very familiar with c++ and compiling, debugging this issue is quite painful for me. If I am unable to resolve it in the coming days, I may consider using rpy2 to call R instead.

tvatter commented 7 months ago

Do you have access to conda/mamba on the HPC environment where you encounter this issue ? If not, you can install it quickly following this link. Then I'd suggest trying the following. Create an environment.yml file with the needed dependencies:

name: pyvinecopulib
channels:
  - conda-forge
dependencies:
  - python=3.10
  - numpy
  - pybind11
  - setuptools_scm

Next step is to create and install this fresh environment via (you can replace mamba by conda if you prefer):

mamba env create -f environment.yml -n pyvinecopulib
mamba activate pyvinecopulib

Finally, try installing the dev branch of pyvinecopulib via

git clone --recursive https://github.com/vinecopulib/pyvinecopulib.git
git checkout dev
pip install ./pyvinecopulib

Can you report on what you see trying this?

singledoggy commented 7 months ago

Actually, I tried compiling in a new conda environment using the environment.yml you provided, and it was still successful:

Building wheels for collected packages: pyvinecopulib
  Building wheel for pyvinecopulib (pyproject.toml) ... done
  Created wheel for pyvinecopulib: filename=pyvinecopulib-0.6.4.dev6-cp310-cp310-linux_x86_64.whl size=1448660 sha256=c3563c6370250ed91c247560c7da67ab511efe1205de0b9b8844e34847015520
  Stored in directory: /localscratch/pip-ephem-wheel-cache-guhekob_/wheels/72/13/d0/20a0b67b33233ccbe150f77e1ff7a2b604227e2a4d28f75db0
Successfully built pyvinecopulib
Installing collected packages: pyvinecopulib
Successfully installed pyvinecopulib-0.6.4.dev6

But I still encountered an error during the import phase:

>>> import pyvinecopulib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /opt/ssoft/apps/2021.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.3.0-hcdyg64/lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /path_to/anaconda3/envs/pyvinecopulib/lib/python3.10/site-packages/pyvinecopulib.cpython-310-x86_64-linux-gnu.so)
singledoggy commented 7 months ago

Update 1:

This may be some important information? I load gcc use module load, and the module show results is here:

$ module show gcc
----------------------------------------------------------------------------------------------------------------------------
   /opt/ssoft/modules/2020.1/compilers/linux-centos7-x86_64/gcc/9.2.0:
----------------------------------------------------------------------------------------------------------------------------
whatis("The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, and Go, as well as libraries for
these languages.")
prepend_path("PATH","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/bin")
prepend_path("MANPATH","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/share/man")
prepend_path("LD_LIBRARY_PATH","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/lib")
prepend_path("LIBRARY_PATH","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/lib")
prepend_path("LD_LIBRARY_PATH","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/lib64")
prepend_path("LIBRARY_PATH","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/lib64")
prepend_path("CPATH","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/include")
prepend_path("CMAKE_PREFIX_PATH","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/")
setenv("CC","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/bin/gcc")
setenv("CXX","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/bin/g++")
setenv("FC","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/bin/gfortran")
setenv("F77","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4/bin/gfortran")
setenv("ROOT_GCC","/opt/ssoft/apps/2020.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.2.0-wqdecm4")
help([[The GNU Compiler Collection includes front ends for C, C++, Objective-C,
Fortran, Ada, and Go, as well as libraries for these languages.
]])

And glibc

$ ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

Update 2

According to the description in the following link, it seems that it is possible to install gcc andlibstdc++.so.6 in a conda virtual environment. I have tried some methods, but pyvinecopulib is unable to read the libstdc++.so.6 in the virtual environment, even after I used export LD_LIBRARY_PATH=/path-to-your-conda/envs/your-env-name/lib:$LD_LIBRARY_PATH.

https://stackoverflow.com/questions/72540359/glibcxx-3-4-30-not-found-for-librosa-in-conda-virtual-environment-after-tryin

singledoggy commented 7 months ago

According to some tutorials ^1, I have found a solution, which seems to be able to modify the rpath and interpreter of python and pyvinecopulib.cpython-310-x86_64-linux-gnu.so using the patchelf^2 library.

Hope this can help those who meet the same question.

!!!PLEASE ALWAYS WORK IN A NEW ENVIRONMENT !!!

!!!OR ELSE YOUR ENV MAY ENCOUNTER PROBLEMS !!!

Step 1 : download libs

a) glibcxx in a hight gcc version^3

b) glibc

c) LIBSTDC++

# skip make dir cd dir
wget https://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/main/g/gcc-13/libstdc%2B%2B6_13.1.0-2ubuntu2\~23.04_amd64.deb
wget http://mirrors.edge.kernel.org/ubuntu/pool/main/g/glibc/libc6-dev_2.39-0ubuntu1_amd64.deb
wget http://mirrors.edge.kernel.org/ubuntu/pool/main/g/glibc/libc6_2.39-0ubuntu1_amd64.deb

d) move them together

# cd previous dir
cp -r lib/x86_64-linux-gnu/* ~/libs/  
cp -r usr/lib/x86_64-linux-gnu/* ~/libs/

Step2: patchelf change

a) Create an environment.yml file with the needed dependencies:

name: pyvinecopulib
channels:
  - conda-forge
dependencies:
  - python=3.10
  - numpy
  - pybind11
  - setuptools_scm
  - patchelf

b) Next step is to create and install this fresh environment via (you can replace mamba by conda if you prefer):

mamba env create -f environment.yml -n pyvinecopulib
mamba activate pyvinecopulib

Then just activate environment and pip install pyvinecopulib

c)change by patchelf

replace path_to_python and path_to_pyvinecopulib.cpython-310-x86_64-linux-gnu.so to your own.

cd ~/libs
patchelf --set-rpath `pwd` + path_to_python
patchelf --set-interpreter `pwd`/ld-linux-x86-64.so.2 +path_to_python
patchelf --set-rpath `pwd` + path_to_pyvinecopulib.cpython-310-x86_64-linux-gnu.so
patchelf --set-interpreter `pwd`/ld-linux-x86-64.so.2 +path_to_pyvinecopulib.cpython-310-x86_64-linux-gnu.so
tvatter commented 7 months ago

OK, I can finally reproduce this error... on a Debian machine. My guess is that the binaries compiled with Ubuntu are not compatible. I am now trying to clone and compile from source. I will report once I understand better what's going on. Things definitely shouldn't be this hard, sorry about that.

tvatter commented 6 months ago

@singledoggy could you let me know the version of gcc used to compile your system python (e.g., via echo -e "import sys\nprint(sys.version)" | python) ? Does it corresponds to the version available by default (above, I think I see 9.2.0) ?

tvatter commented 6 months ago

@singledoggy And finally, can you let me know the glibcx ABIs that are currently available on your system (e.g., via strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCX, although your path for the system libstdc++.so.6 might be different on the HPC)

tvatter commented 6 months ago

Regarding this issue, what I think is happening: the wheel was prepared by triggering a Github action using a compiler having access to a later version of GLIBCX. I think that we need to both (a) ensure that the compiler/GLIBCX requirement is specified, and (b) use the lowest possible gcc version to build the wheel.

tvatter commented 6 months ago

OK, I believe that I've found the issue.

TL;DR @singledoggy it's not you it's us

Our wheels seem to not be properly portable.

Can you also report on what's going on if you install from source instead of from the wheel?

E.g. pip install pyvinecopulib --no-binary ":all:"

This should solve your issue

singledoggy commented 6 months ago

Thank you for your work. Here are the results in my environment:

version of gcc python

In a new conda environment pyvinecopulib I mentioned above:

$ echo -e "import sys\nprint(sys.version)" | python
3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:36:39) [GCC 12.3.0]

glibcx ABIs that are currently available

I loaded gcc 9.3.0 this time(highest I can load through module load) so:

strings /opt/ssoft/apps/2021.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.3.0-hcdyg64/lib64/libstdc++.so.6 | grep GLIBCX
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_DEBUG_MESSAGE_LENGTH
_ZNKSt14basic_ifstreamIcSt11char_traitsIcEE7is_openEv@GLIBCXX_3.4
_ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEv@@GLIBCXX_3.4.5
_ZNKSbIwSt11char_traitsIwESaIwEE11_M_disjunctEPKw@GLIBCXX_3.4
_ZNKSt14basic_ifstreamIwSt11char_traitsIwEE7is_openEv@@GLIBCXX_3.4.5
GLIBCXX_3.4.21
GLIBCXX_3.4.9
_ZSt10adopt_lock@@GLIBCXX_3.4.11
GLIBCXX_3.4.10
GLIBCXX_3.4.16
GLIBCXX_3.4.1
_ZNSt19istreambuf_iteratorIcSt11char_traitsIcEEppEv@GLIBCXX_3.4
GLIBCXX_3.4.28
_ZNSs7_M_copyEPcPKcm@GLIBCXX_3.4
GLIBCXX_3.4.25
_ZNSt19istreambuf_iteratorIcSt11char_traitsIcEEppEv@@GLIBCXX_3.4.5
_ZNSs7_M_moveEPcPKcm@@GLIBCXX_3.4.5
_ZNKSt13basic_fstreamIwSt11char_traitsIwEE7is_openEv@GLIBCXX_3.4
_ZNKSt13basic_fstreamIcSt11char_traitsIcEE7is_openEv@GLIBCXX_3.4
_ZNSbIwSt11char_traitsIwESaIwEE4_Rep26_M_set_length_and_sharableEm@@GLIBCXX_3.4.5
_ZNSs4_Rep26_M_set_length_and_sharableEm@GLIBCXX_3.4
_ZSt10defer_lock@@GLIBCXX_3.4.11
_ZN10__gnu_norm15_List_node_base4swapERS0_S1_@@GLIBCXX_3.4
_ZNSs9_M_assignEPcmc@@GLIBCXX_3.4.5
_ZNKSbIwSt11char_traitsIwESaIwEE15_M_check_lengthEmmPKc@@GLIBCXX_3.4.5
_ZNKSt14basic_ifstreamIcSt11char_traitsIcEE7is_openEv@@GLIBCXX_3.4.5
_ZNSbIwSt11char_traitsIwESaIwEE7_M_moveEPwPKwm@GLIBCXX_3.4
GLIBCXX_3.4.24
_ZNVSt9__atomic011atomic_flag12test_and_setESt12memory_order@@GLIBCXX_3.4.11
GLIBCXX_3.4.20
_ZNSt11char_traitsIwE2eqERKwS2_@@GLIBCXX_3.4.5
GLIBCXX_3.4.12
_ZNSi6ignoreEv@@GLIBCXX_3.4.5
GLIBCXX_3.4.2
_ZNSt11char_traitsIcE2eqERKcS2_@@GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.15
_ZNKSt13basic_fstreamIcSt11char_traitsIcEE7is_openEv@@GLIBCXX_3.4.5
_ZNSs9_M_assignEPcmc@GLIBCXX_3.4
GLIBCXX_3.4.19
_ZNKSt14basic_ofstreamIwSt11char_traitsIwEE7is_openEv@GLIBCXX_3.4
_ZNSt19istreambuf_iteratorIwSt11char_traitsIwEEppEv@GLIBCXX_3.4
GLIBCXX_3.4.27
_ZN10__gnu_norm15_List_node_base7reverseEv@@GLIBCXX_3.4
_ZN10__gnu_norm15_List_node_base4hookEPS0_@@GLIBCXX_3.4
_ZNSt11char_traitsIwE2eqERKwS2_@GLIBCXX_3.4
_ZNSbIwSt11char_traitsIwESaIwEE7_M_copyEPwPKwm@GLIBCXX_3.4
_ZNSbIwSt11char_traitsIwESaIwEE7_M_copyEPwPKwm@@GLIBCXX_3.4.5
GLIBCXX_3.4.23
GLIBCXX_3.4.3
GLIBCXX_3.4.7
_ZNSi6ignoreEl@@GLIBCXX_3.4.5
_ZNKSbIwSt11char_traitsIwESaIwEE11_M_disjunctEPKw@@GLIBCXX_3.4.5
_ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEv@GLIBCXX_3.4
_ZNKSt13basic_fstreamIwSt11char_traitsIwEE7is_openEv@@GLIBCXX_3.4.5
_ZNSbIwSt11char_traitsIwESaIwEE7_M_moveEPwPKwm@@GLIBCXX_3.4.5
GLIBCXX_3.4.18
_ZNSbIwSt11char_traitsIwESaIwEE4_Rep26_M_set_length_and_sharableEm@GLIBCXX_3.4
_ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEl@@GLIBCXX_3.4.5
_ZSt15future_category@@GLIBCXX_3.4.14
_ZNSi6ignoreEl@GLIBCXX_3.4
_ZNSt11char_traitsIcE2eqERKcS2_@GLIBCXX_3.4
_ZNKSs15_M_check_lengthEmmPKc@GLIBCXX_3.4
_ZN10__gnu_norm15_List_node_base8transferEPS0_S1_@@GLIBCXX_3.4
_ZNSbIwSt11char_traitsIwESaIwEE9_M_assignEPwmw@GLIBCXX_3.4
_ZNVSt9__atomic011atomic_flag5clearESt12memory_order@@GLIBCXX_3.4.11
_ZNKSt14basic_ofstreamIcSt11char_traitsIcEE7is_openEv@@GLIBCXX_3.4.5
_ZNKSt14basic_ofstreamIcSt11char_traitsIcEE7is_openEv@GLIBCXX_3.4
_ZNSs7_M_moveEPcPKcm@GLIBCXX_3.4
_ZNSt13basic_istreamIwSt11char_traitsIwEE6ignoreEl@GLIBCXX_3.4
_ZNSbIwSt11char_traitsIwESaIwEE9_M_assignEPwmw@@GLIBCXX_3.4.5
_ZNKSbIwSt11char_traitsIwESaIwEE15_M_check_lengthEmmPKc@GLIBCXX_3.4
_ZNKSs11_M_disjunctEPKc@@GLIBCXX_3.4.5
_ZN10__gnu_norm15_List_node_base6unhookEv@@GLIBCXX_3.4
GLIBCXX_3.4.22
_ZNSt19istreambuf_iteratorIwSt11char_traitsIwEEppEv@@GLIBCXX_3.4.5
_ZNSi6ignoreEv@GLIBCXX_3.4
_ZNSs7_M_copyEPcPKcm@@GLIBCXX_3.4.5
GLIBCXX_3.4.8
GLIBCXX_3.4.13
_ZSt11try_to_lock@@GLIBCXX_3.4.11
_ZNKSt14basic_ofstreamIwSt11char_traitsIwEE7is_openEv@@GLIBCXX_3.4.5
GLIBCXX_3.4.17
GLIBCXX_3.4.4
_ZNKSs15_M_check_lengthEmmPKc@@GLIBCXX_3.4.5
_ZNKSt14basic_ifstreamIwSt11char_traitsIwEE7is_openEv@GLIBCXX_3.4
_ZNSs4_Rep26_M_set_length_and_sharableEm@@GLIBCXX_3.4.5
GLIBCXX_3.4.26
_ZNKSs11_M_disjunctEPKc@GLIBCXX_3.4

pip install pyvinecopulib --no-binary ":all:"

import pyvinecopulib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /opt/ssoft/apps/2021.1/linux-centos7-x86_64/gcc-4.8.5/gcc-9.3.0-hcdyg64/lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /Users/mgao2/anaconda3/envs/pyvinecopulib/lib/python3.10/site-packages/pyvinecopulib.cpython-310-x86_64-linux-gnu.so)
tvatter commented 6 months ago

Thanks a lot for checking again. Sorry, I wrote many messages while trying to figure things out, but I think that you can discard pretty much everything except the last one. Installing from source should work in any environment, as I think that the issue lies in how we packaged the wheels.

singledoggy commented 6 months ago

I guess you need certain gcc version higher than 9.3 to compile from source. Otherwise you will still get an Import error.

---- Replied Message ---- | From | Thibault @.> | | Date | 02/29/2024 22:02 | | To | vinecopulib/pyvinecopulib @.> | | Cc | Han @.>, Mention @.> | | Subject | Re: [vinecopulib/pyvinecopulib] GLIBC_2.29 required when import pyvinecopulib (Issue #119) |

Thanks a lot for checking again. Sorry, I wrote many messages while trying to figure things out, but I think that you can discard pretty much everything except the last one. Installing from source should work in any environment, as I think that the issue lies in how we packaged the wheels.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

tvatter commented 6 months ago

So you were able to compile with pip install pyvinecopulib --no-binary ":all:" in a fresh conda env (no pathref modif needed) but still got the import error? Btw, I'm working a more portable build at the moment, sorry about this.

singledoggy commented 6 months ago

Yes. It's where I start this discussion.

---- Replied Message ---- | From | Thibault @.> | | Date | 02/29/2024 22:14 | | To | vinecopulib/pyvinecopulib @.> | | Cc | Han @.>, Mention @.> | | Subject | Re: [vinecopulib/pyvinecopulib] GLIBC_2.29 required when import pyvinecopulib (Issue #119) |

So you were able to compile with pip install pyvinecopulib --no-binary ":all:" in a fresh conda env (no pathref modif needed) but still got the import error? Btw, I'm working a more portable build at the moment, sorry about this.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

tvatter commented 6 months ago

Dang, OK. Well, let's hope that my portable builds fix things. FWIW, I'm trying to use manylinux2014, can you check at the link if it would be compatible with your system ?

singledoggy commented 6 months ago

I guess it would be compatibale with my system. And thanks again for your selfless work.

---- Replied Message ---- | From | Thibault @.> | | Date | 02/29/2024 22:29 | | To | vinecopulib/pyvinecopulib @.> | | Cc | Han @.>, Mention @.> | | Subject | Re: [vinecopulib/pyvinecopulib] GLIBC_2.29 required when import pyvinecopulib (Issue #119) |

Dang, OK. Well, let's hope that my portable builds fix things. FWIW, I'm trying to use manylinux2014, can you check at the link if it would be compatible with your system ?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

tvatter commented 6 months ago

Version 0.6.5 is now available on PyPi and the binaries are now properly portable. It should work "as is" on most Linux, macos, and windows computers. Can you please test whether it now works for you in a fresh environment (without all the glib install and patchelf stuff) ? I've tested on a few systems and it seems to work, so I'm going to close for now, but feel free to reopen otherwise.