近日朋友向我求助说是在CentOS6中编译安装了python2.7后面不知怎么搞的yum也用不了的,本以为很简单的事情,把yum里的头替换一下就好了,结果事情不是那个简单。
参考这篇文章重装 https://www.lizenghai.com/archives/17330.html,所使用的包如下:
libxml2-python-2.7.6-21.el6_8.1.x86_64.rpm
python-2.6.6-66.el6_8.x86_64.rpm
python-backports-1.0-5.el6.x86_64.rpm
python-backports-ssl_match_hostname-3.4.0.2-5.el6.noarch.rpm
python-chardet-2.2.1-1.el6.noarch.rpm
python-devel-2.6.6-66.el6_8.x86_64.rpm
python-iniparse-0.3.1-2.1.el6.noarch.rpm
python-libs-2.6.6-66.el6_8.x86_64.rpm
python-pycurl-7.19.0-9.el6.x86_64.rpm
python-setuptools-0.6.10-4.el6_9.noarch.rpm
python-urlgrabber-3.9.1-11.el6.noarch.rpm
rpm-build-4.8.0-59.el6.x86_64.rpm
rpm-libs-4.8.0-59.el6.x86_64.rpm
rpm-python-4.8.0-59.el6.x86_64.rpm
yum-3.2.29-81.el6.centos.noarch.rpm
yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
yum-plugin-aliases-1.1.30-41.el6.noarch.rpm
yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm
yum-utils-1.1.30-41.el6.noarch.rpm
下面这些是一些记录,看不懂可忽略这一段 rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制清除已安装的程序及其关联 whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令 whereis python ##验证删除,返回无结果说明清除干净 删除现有的yum [root@localhost rx]# rpm -qa|grep yum yum-metadata-parser-1.1.2-16.el6.x86_64 yum-plugin-aliases-1.1.30-41.el6.noarch yum-plugin-fastestmirror-1.1.30-41.el6.noarch yum-plugin-protectbase-1.1.30-41.el6.noarch yum-3.2.29-81.el6.centos.noarch yum-utils-1.1.30-41.el6.noarch rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps 创建一个目录:python-need-pkg,将这些包下载下来,我是用centos6.10 DVD1 ios 镜像中提取的包。下载响应的包(注意:根据自己的系统下载,源中版本会更新,具体查看URL中的版本再下载!) 5.执行命令安装 1>执行这一步的时候没有依赖问题 rpm -Uvh --replacepkgs python*.rpm 行这一步的时候报依赖问题,有两个, rpm -Uvh --replacepkgs rpm-python.rpm yum.rpm error: Failed dependencies: libxml2-python is needed by yum-utils-1.1.30-41.el6.noarch rpm -ivh --force yum-utils-1.1.30-41.el6.noarch.rpm find /usr/lib64/ -type f -name "*.so" | xargs nm -AD | grep PyUnicodeUCS4_AsUTF8String /usr/lib64/python2.6/lib-dynload/_sqlite3.so: U PyUnicodeUCS4_AsUTF8String /usr/lib64/python2.6/lib-dynload/cPickle.so: U PyUnicodeUCS4_AsUTF8String /usr/lib64/python2.6/site-packages/rpm/_rpmmodule.so: U PyUnicodeUCS4_AsUTF8String rpm -qf /usr/lib64/python2.6/lib-dynload/_sqlite3.so python-libs-2.6.6-66.el6_8.x86_64 rpm -qf /usr/lib64/python2.6/lib-dynload/cPickle.so python-libs-2.6.6-66.el6_8.x86_64 rpm -qf /usr/lib64/python2.6/site-packages/rpm/_rpmmodule.so rpm-python-4.8.0-59.el6.x86_64 nm -AD /lib/libpython2.6.so.1.0 | grep PyUnicodeUCS4_AsUTF8String libpython2.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00007f139db99000) libpython2.6.so.1.0 => /lib/libpython2.6.so.1.0 (0x00007f6be9933000) libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007f139cb90000) libnssutil3.so => /usr/lib/libnssutil3.so (0x00007f6be892a000)
后面重装了系统自己带的python2.6.6及yum也还是报 /usr/lib64/python2.6/site-packages/rpm/_rpmmodule.so undefined symbol:PyUnicodeUCS4_AsUTF8String
后面自己在虚拟机中安装了一个干净的CentOS6.10对比才发现问题所在。下面这个是干净系统的 ldd
[root@localhost ~]# ldd /usr/lib64/python2.6/site-packages/rpm/_rpmmodule.so linux-vdso.so.1 => (0x00007fff9c3e9000) librpm.so.1 => /usr/lib64/librpm.so.1 (0x00007f6a00ddf000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f6a00bc0000) libcap.so.2 => /lib64/libcap.so.2 (0x00007f6a009bb000) libacl.so.1 => /lib64/libacl.so.1 (0x00007f6a007b3000) libdb-4.7.so => /lib64/libdb-4.7.so (0x00007f6a0043e000) librpmio.so.1 => /usr/lib64/librpmio.so.1 (0x00007f6a0020e000) libnss3.so => /usr/lib64/libnss3.so (0x00007f69ffec6000) libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f69ffcb5000) libz.so.1 => /lib64/libz.so.1 (0x00007f69ffa9e000) libelf.so.1 => /usr/lib64/libelf.so.1 (0x00007f69ff888000) libpopt.so.0 => /lib64/libpopt.so.0 (0x00007f69ff67f000) liblzma.so.0 => /usr/lib64/liblzma.so.0 (0x00007f69ff45d000) liblua-5.1.so => /usr/lib64/liblua-5.1.so (0x00007f69ff230000) libm.so.6 => /lib64/libm.so.6 (0x00007f69fefac000) libpython2.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00007f69fec05000) librt.so.1 => /lib64/librt.so.1 (0x00007f69fe9fd000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f69fe7e0000) libc.so.6 => /lib64/libc.so.6 (0x00007f69fe44b000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f69fe247000) /lib64/ld-linux-x86-64.so.2 (0x00005617d7672000) libattr.so.1 => /lib64/libattr.so.1 (0x00007f69fe042000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f69fde2b000) libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007f69fdbfc000) libplc4.so => /lib64/libplc4.so (0x00007f69fd9f7000) libplds4.so => /lib64/libplds4.so (0x00007f69fd7f2000) libnspr4.so => /lib64/libnspr4.so (0x00007f69fd5b3000) libutil.so.1 => /lib64/libutil.so.1 (0x00007f69fd3af000)
对比发现这两处不一样:
libpython2.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00007f139db99000)
libpython2.6.so.1.0 => /lib/libpython2.6.so.1.0 (0x00007f6be9933000)
libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007f139cb90000)
libnssutil3.so => /usr/lib/libnssutil3.so (0x00007f6be892a000)
解决它:
cd /etc/ld.so.conf.d/
echo "/usr/lib64/" > libnssutil3.conf
echo "/usr/lib64/" > libpython2.6.conf
echo "/lib64/" > libdb-4.7.conf
又遇到 无法 import time 的问题,解决方法:
vim /etc/profile.d/python.sh export PYTHONPATH=$PYTHONPATH:/usr/lib64/python2.6:/usr/lib64/python2.6/lib-dynload/
文章评论
不好,有细作 XD