前言:
CentOS 6.X上面安装的python默认版本为2.6.6,但是现在很多库都是要求python2.7,因此一个新系统上面要做的第一件事就是升级Python。
0.安装依赖包
-
[root@localhost ~]# python --version
-
Python 2.6.6
-
[root@localhost ~]# yum -y update
-
[root@localhost ~]# yum groupinstall "Development tools"
-
[root@localhost ~]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
1.安装Python2.7
-
[root@localhost ~]# wget
-
[root@localhost ~]# tar xf Python-2.7.10.tar.xz
-
[root@localhost ~]# cd Python-2.7.10
-
[root@localhost ~]# ./configure --prefix=/usr/local
-
[root@localhost ~]# make && make altinstall #这里是因为系统上有两个不同版本的Python
-
[root@localhost ~]# mv /usr/bin/python /usr/bin/python2.6.6
-
[root@localhost ~]# ln -s /usr/local/bin/python2.7 /usr/bin/python
然后编辑/usr/bin/yum,把第一行的#!/usr/bin/python修改成#!/usr/bin/python2.6.6
这样执行yum命令已经不会出现之前的错误信息了。
此时执行python -V如果出现如下错误:
error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
编辑配置文件vi /etc/ld.so.conf
添加新的一行内容/usr/local/lib,保存退出。然后执行如下命令:
/sbin/ldconfig
/sbin/ldconfig -v
2.安装pip
下载最新版的pip,然后安装:
-
[root@localhost ~]# wget
-
[root@localhost ~]# python get-pip.py
-
[root@localhost ~]# whereis pip #查找pip的位置
-
[root@localhost ~]# ln -s /usr/local/bin/pip2.7 /usr/bin/pip #找到pip2.7的路径,然后为其创建软链接作为默认
至此pip安装完毕,可以正常使用了。
参考文献:
1.
2. http://blog.ruterly.com/2015/12/03/Update-python/
3.
安装方法2:
-
yum install -y gcc gcc-c++ make readline readline-devel zlib zlib-devel openssl openssl-devel
-
-
wget
-
tar xf Python-2.7.10.tgz
-
cd Python-2.7.10
-
./configure --prefix=/usr/local/python2.7 --enable-shared
-
sed -i "s/^#readline\ readline.c/readline\ readline.c/g" Modules/Setup # 解决调试时按上下左右出现乱码的问题
-
-
make && make install
-
-
grep '/usr/local/python2.7/lib' /etc/ld.so.conf &> /dev/null || echo '/usr/local/python2.7/lib' >> /etc/ld.so.conf
-
ldconfig
-
grep '/usr/local/python2.7/bin' /etc/profile &> /dev/null || echo 'export PATH=/usr/local/python2.7/bin:$PATH' >> /etc/profile
-
-
source /etc/profile
-
-
# 安装pip
-
curl -sSL | python2.7
阅读(1474) | 评论(0) | 转发(0) |