CentOS7安装Py3.68替换默认python版本

1、安装python的一些依赖环境、库等
yum -y install zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi libffi-devel -y

2、下载软件、解压缩
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
tar xf Python-3.6.8.tgz

3、编译安装
./configure –prefix=/usr/python –enable-shared CFLAGS=-fPIC
make -j 4
make install

4、由于yum等依赖python2 环境,所以需要先修改python shebang(环境)
vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down
修改以上两个文件
#!/usr/bin/python ===> #!/usr/bin/python2

5、修改默认python版本
rm -rf /usr/bin/python
ln -s /usr/python/bin/python3 /usr/bin/python
ln -s /usr/python/bin/pip3 /usr/bin/pip3

遇到的问题:
有一个库文件,没有找到
bin]# ./python3 –version
./python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

bin]# ldd ./python3
linux-vdso.so.1 => (0x00007ffc907ef000)
libpython3.6m.so.1.0 => not found
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f6e1b2aa000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f6e1b0a6000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f6e1aea3000)
libm.so.6 => /lib64/libm.so.6 (0x00007f6e1aba0000)
libc.so.6 => /lib64/libc.so.6 (0x00007f6e1a7dd000)
/lib64/ld-linux-x86-64.so.2 (0x000055d9ff1eb000)

find / -name libpython3.6m.so.1.0
/usr/python/lib/libpython3.6m.so.1.0
说明安装了,但是在系统里找不到该库

最简单解决办法,copy之到系统库里
cp /usr/python/lib/libpython3.6m.so.1.0 /lib64/

发表评论