背景
centos6.5 python 默认版本是2.6 但是由于开发需要用到python2.7,所以需要做版本升级操作
升级2.7
- 去官网下载要安装的对应版本的python的源代码
下载地址 下载对应版本
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
- 解压
tar -zxvf Python-2.7.15.tgz
- 配置
cd Python-2.7.15 #找到对应目录
./configure #进行配置
[root@centos6 Python-2.7.15]# ./configure
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python2.7... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux2
checking EXTRAPLATDIR...
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/develop/Python-2.7.15':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
configure: error: no acceptable C compiler found in $PATH
这是gcc不存在。所以要进行安装gcc
yum -y install gcc
- 编译 安装
make && make install
- 注意安装后的目录在
[root@centos6 bin]# ll /usr/local/bin/
总用量 6172
-rwxr-xr-x. 1 root root 101 1月 9 03:41 2to3
-rwxr-xr-x. 1 root root 99 1月 9 03:41 idle
-rwxr-xr-x. 1 root root 84 1月 9 03:41 pydoc
lrwxrwxrwx. 1 root root 7 1月 9 03:42 python -> python2
lrwxrwxrwx. 1 root root 9 1月 9 03:42 python2 -> python2.7
-rwxr-xr-x. 1 root root 6283217 1月 9 03:41 python2.7
-rwxr-xr-x. 1 root root 1687 1月 9 03:42 python2.7-config
lrwxrwxrwx. 1 root root 16 1月 9 03:42 python2-config -> python2.7-config
lrwxrwxrwx. 1 root root 14 1月 9 03:42 python-config -> python2-config
-rwxr-xr-x. 1 root root 18547 1月 9 03:41 smtpd.py
可以同时用2.6跟2.7版本 如下
[root@centos6 bin]# python
Python 2.7.15 (default, Jan 9 2019, 03:40:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@centos6 bin]# python2.6
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@centos6 bin]#
PS
这时候使用的时候会发现pip不可用,这时候得看下安装pip
python2.6升级2.7安装pip
完成
[root@centos6 Python-2.7.15]# python
Python 2.7.15 (default, Jan 8 2019, 18:31:23)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>