1
error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

在linux(centos)中编译安装python完成后,运行python3或python3 -V命令时,可能会报错

1
error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

原因

centos系统默认加载/usr/lib,/lib下面库文件,python默认安装到非此类文件夹。(引自https://blog.csdn.net/learner198461/article/details/54598895)

解决办法

将python3安装目录的lib目录下的文件libpython3.6m.so.1.0复制到/usr/lib/目录下

1
cp /usr/local/python3/lib/libpython3.6m.so.1.0 /usr/lib/

将目录/usr/lib/添加到/etc/ld.so.conf.d/目录下的python3.6.conf文件中

1
echo "/usr/lib" > /etc/ld.so.conf.d/python3.6.conf

运行命令

1
ldconfig

再运行 python3 或python3 -V,发现没有上述错误了

将python3安装目录的lib目录下的文件libpython3.6m.so.1.0复制到/usr/lib64/目录下即可

1
cp /usr/local/python3/lib/libpython3.6m.so.1.0 /usr/lib64