用 conda 虚拟环境跑代码,import scipy 时报错:
ImportError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /data/itom/miniconda3/envs/cu116_pt1131/lib/python3.9/site-packages/scipy/spatial/_ckdtree.cpython-39-x86_64-linux-gnu.so)
参考 [1],一种解法是把所用的 conda 虚拟环境的 lib/ 加入到 LD_LIBRARY_PATH
。为自动导入,可在 ~/.bashrc 中加入:
- 假设 miniconda3 的安装路径是 ~/miniconda3/
# ~/.bashrc 内
if [ -d $HOME/miniconda3/envs ]; thenld_lib_path=""for d in `ls $HOME/miniconda3/envs`; doif [ -z $ld_lib_path ]; thenld_lib_path=$HOME/miniconda3/envs/$d/libelseld_lib_path=$ld_lib_path:$$HOME/miniconda3/envs/$d/libfidoneif [ ! -z $ld_lib_path ]; thenif [ -z $LD_LIBRARY_PATH ]; thenexport LD_LIBRARY_PATH=$ld_lib_pathelseexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ld_lib_pathfifi
fi
References
- Anaconda ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21’ not found
- ImportError: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29’ not found #11417
- ImportError: `GLIBCXX_3.4.30’ not found #1282