在安装完CentOS 6.7和software update后,我们发现python的版本是2.6.6。由于需要将python升级到3.5,只能采取编译安装。
1. 下载安装源
# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
2. 将下载的压缩包移动到目标目录下
# mv /home/***/Desktop/Python-3.5.2.tgz /usr/local/
3. 解压压缩包
# tar zxvf Python-3.5.0.tgz
4. 进入Python-3.5.2,进行简单的配置
(1)# cd /usr/local/Python-3.5.2
(2)# ./configure --prefix=/usr/local/Python-3.5.2
在这一步遇到了问题:
[root@CentOS6 Python-3.5.2]# ./configure --prefix=/usr/local/Python-3.5.2 checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... linux checking for --without-gcc... no checking for --with-icc... no checking for gcc... no checking for cc... no checking for cl.exe... no <span style="color:#ff0000;">configure: error: in `/usr/local/Python-3.5.2': configure: error: no acceptable C compiler found in $PATH</span> See `config.log' for more details原因:缺少gcc编译环境
解决方法:配置yum,可以用yum install -y gcc
(3)# make
(4)# make install
这一步遇到了问题:<span style="font-size:14px;">Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS</span>原因:
因为SSL没有安装
解决方法:
执行命令yum install openssl-devel进行安装
然后再执行make install。编译成功
# mv /usr/bin/python /usr/bin/python_old
更改yum的配置文件
修改vim的配置vim /usr/bin/yum
将#!/usr/bin/python更改为#!/usr/bin/python_old
6. 在/usr/local/Python-3.5.2 找到可执行文件python(绿色的),运行一次
# cd /usr/local/Python-3.5.2/
# ./python
(版本是3.5.2)
# (键盘:Ctrl + D)
7. 修改老版本python的链接指向(可能会影响到yum的使用)
# ln -s /usr/local/Python-3.5.2/python /usr/bin/python
8. 运行python命令
# python
(进入python 3.5.2 的世界)
9.安装easy_install、pip安装ezsy_install:
wget -q http://peak.telecommunity.com/dist/ez_setup.py
python ez_install.py
遇到错误:
[root@CentOS6 /]# python ez_setup.py File "ez_setup.py",line 106 except pkg_resources.VersionConflict,e:原因是因为这个py文件是用的python2的语法,改成python3的就可以了:
except pkg_resources.VersionConflict,e改成except pkg_resources.VersionConflict as e
print加括号。
再python ez_setup成功。
返回如下类似信息就是安装成功:
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11
建立软链接(否则不能用):
ln -s /usr/local/Python-3.5.2/bin/easy_install /usr/bin/easy_install
测试:
easy_install --version
setuptools 26.1.1 from /usr/local/Python-3.5.2/lib/python3.5/site-packages/setuptools-26.1.1-py3.5.egg (Python 3.5)
安装pip:
wget --no-check-certificate https://github.com/pypa/pip/archive/1.5.6.tar.gz
tar zvxf 1.5.6 #解压文件
cd pip-1.5.6/
python setup.py install
这样就安装成功pip了。
返回如下类似信息就是安装成功:
Processing dependencies for pip==1.5.6
Finished processing dependencies for pip==1.5.6
建立软链接(否则不能用):
ln -s /usr/local/Python-3.5.2/bin/pip /usr/bin/pip
测试:
pip --version
pip 1.5.6 from /usr/local/Python-3.5.2/lib/python3.5/site-packages/pip-1.5.6-py3.5.egg (python 3.5)
转载:http://www.cnblogs.com/freescale/p/4924810.html