更新centos的python版本

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/wxm6614/article/details/55060119

以下脚本在阿里云服务器上测试通过

echo “upgrade python version from 2.6.6 to 2.7"
yum install -y gcc zlib-devel  openssl-devel
wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
tar zxvf Python-2.7.9.tgz
./configure --prefix=/usr/local/  
make && make install
#将系统默认的python指向python2.7版本
mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/bin/python2.7 /usr/bin/python

#解决系统 Python 软链接指向 Python2.7 版本后,
#因为yum是不兼容 Python 2.7的,所以yum不能正常工作,我们需要指定 yum 的Python版本
vi /usr/bin/yum
#!/usr/bin/python
改成
#!/usr/bin/python2.6.6

备注测试 easy_install 命令会有问题

[xxxx]# easy_install
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2603, in <module>
  File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 666, in require
  File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: distribute==0.6.10
解决办法: rpm -qa |grep distribute 发现没有该包,所以安装
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz
tar zxvf distribute-0.6.49.tar.gz && cd distribute-0.6.49  && python setup.py  install
再次执行
[xxxx]#easy_install
error: No urls, filenames, or requirements specified (see --help)

[root@iZ25lx34hhyZ distribute-0.6.49]# pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.49-py2.7.egg/pkg_resources.py", line 2877, in <module>
    working_set.require(__requires__)
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.49-py2.7.egg/pkg_resources.py", line 698, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.49-py2.7.egg/pkg_resources.py", line 596, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==2.7.9
解决办法:
 easy_install pip
修改版本号
vim  /usr/bin/pip  将2.7.9改成你安装的pip即可

当执行ipython notebook …..的时候提示缺少_sqlite3.so
解决办法:可以将机器上原有的so拷过去
find / -name _sqlite3.so
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/
展开阅读全文

没有更多推荐了,返回首页