站点图标 ITGeeker技术奇客

升级Python到2.7.15 on CentOS 6 x64

Centos 6 自带的2.6版本队友有些情况总会出现各种错误,例如:

File "/usr/lib/python2.6/site-packages/pip/_internal/index.py", line 526 
{str(c.version) for c in all_candidates}, ^ 
SyntaxError: invalid syntax

明确你的Linux版本

cat /etc/redhat-release

安装依赖:

yum groupinstall -y "Development tools"
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

下载最新版本并编译安装

cd /tmp
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
tar zxf Python-2.7.15.tgz
cd Python-2.7.15
./configure
make && make install

#新版目录

ll -tr /usr/local/bin/python*

#系统自带老版本目录

ll -tr /usr/bin/python*

备份老版本命令,创建新版本软连接

mv /usr/bin/python /usr/bin/python.old
rm -f /usr/bin/python-config
ln -s /usr/local/bin/python /usr/bin/python && ln -s /usr/local/bin/python-config /usr/bin/python-config && ln -s /usr/local/include/python2.7/ /usr/include/python2.7

检查一下是否正确

python --version

为新版 Python 安装 setuptools

wget https://bootstrap.pypa.io/ez_setup.py -O - | python
easy_install pip

然后就可以pip安装了

pip install itgeeker
退出移动版