在CentOS 6.X 上面安装 Python 2.7.X

/ 0评 / 0

CentOS 6.X 自带的python版本是 2.6 , 由于工作需要,很多时候需要2.7版本。所以需要进行版本升级。由于一些系统工具和服务是对 Python 有依赖的,所以升级 Python 版本需要注意。

升级步骤

如何欢乐的,没有痛苦的升级python版本 ,往下看 …

更新系统和开发工具集

更新指令

yum -<span class="keyword">y</span> <span class="keyword">update</span>
yum groupinstall -<span class="keyword">y</span> <span class="string">'development tools'</span>

另外还需要安装 python 工具需要的额外软件包 SSL, bz2, zlib

yum <span class="operator"><span class="keyword">install</span> -y zlib-devel bzip2-devel openssl-devel xz-libs wget</span>

源码安装Python 2.7.x

wget <span class="symbol">http:</span>/<span class="regexp">/www.python.org/ftp</span><span class="regexp">/python/</span><span class="number">2.7</span>.<span class="number">8</span>/<span class="constant">Python</span>-<span class="number">2.7</span>.<span class="number">8</span>.tar.xz
xz -d <span class="constant">Python</span>-<span class="number">2.7</span>.<span class="number">8</span>.tar.xz
tar -xvf <span class="constant">Python</span>-<span class="number">2.7</span>.<span class="number">8</span>.tar

安装详情:

<span class="preprocessor"># 进入目录:</span>
cd Python-<span class="number">2.7</span><span class="number">.8</span>
<span class="preprocessor"># 运行配置 configure:</span>
./configure --prefix=/usr/local
<span class="preprocessor"># 编译安装:</span>
make
make altinstall
<span class="preprocessor"># 检查 Python 版本:</span>
[root@dbmasterxxx ~]# python2<span class="number">.7</span> -V
Python <span class="number">2.7</span><span class="number">.8</span>

设置 PATH

为了我们能够方便的使用Python,我们需要设置系统变量或者建立 软连接将新版本的 Python
加入到 path 对应的目录 :

mv /usr/bin/python /usr/bin/python2.6.6 
ln -<span class="keyword">s</span> /usr/<span class="keyword">local</span>/bin/python2.<span class="number">7</span>  /usr/bin/python
<span class="comment"># 检查</span>
[root<span class="variable">@dbmasterxxx</span> ~]<span class="comment"># python -V</span>
Python <span class="number">2.7</span>.<span class="number">8</span>
[root<span class="variable">@dbmasterxxx</span> ~]<span class="comment"># which python </span>
/usr/bin/python

安装 setuptools

<span class="preprocessor">#获取软件包</span>
wget --no-check-certificate https:<span class="comment">//pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz</span>
<span class="preprocessor"># 解压:</span>
tar -xvf setuptools-<span class="number">1.4</span><span class="number">.2</span>.tar.gz
cd setuptools-<span class="number">1.4</span><span class="number">.2</span>
<span class="preprocessor"># 使用 Python 2.7.8 安装 setuptools</span>
python2<span class="number">.7</span> setup.py install

安装 PIP

curl  http<span class="variable">s:</span>//bootstrap.pypa.io/<span class="built_in">get</span>-pip.<span class="keyword">py</span> | python2.<span class="number">7</span> -

修复 yum 工具

此时yum应该是失效的,因为此时默认python版本已经是2.7了。而yum需要的是2.6 所以:

[root<span class="variable">@dbmasterxxx</span> ~]<span class="comment"># which yum </span>
/usr/bin/yum
<span class="comment">#修改 yum中的python </span>
将第一行  <span class="comment">#!/usr/bin/python  改为 #!/usr/bin/python2.6</span>
此时yum就ok啦

总结

<span class="title">Python</span> 版本升级过很多遍,每次都有问题,此方法来自互联网,经过使用,没有问题,特此总结一下

发表评论

邮箱地址不会被公开。 必填项已用*标注