用 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/
shell
# ~/.bashrc 内
if [ -d $HOME/miniconda3/envs ]; then
ld_lib_path=""
for d in `ls $HOME/miniconda3/envs`; do
if [ -z $ld_lib_path ]; then
ld_lib_path=$HOME/miniconda3/envs/$d/lib
else
ld_lib_path=$ld_lib_path:$$HOME/miniconda3/envs/$d/lib
fi
done
if [ ! -z $ld_lib_path ]; then
if [ -z $LD_LIBRARY_PATH ]; then
export LD_LIBRARY_PATH=$ld_lib_path
else
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ld_lib_path
fi
fi
fi