首页 > 编程 > Python > 正文

python2.6.6如何升级到python2.7.14

2020-02-22 23:37:30
字体:
来源:转载
供稿:网友

其实网上有很多关于python2.6.6 升级到python2.7的文章,但是我对比这些类似的文章升级之后,发现其中有错误的地方,于是决定还是自己写一个真正的升级过程。

我的虚拟机里安装的是CentOS 6.5里面默认安装的Python2.6.6,因为要学习TensorFlow,所以决定升级到2.7

1、下载安装包

其实在python官网上有个目录列举出了各个版本的下载安装包,点击这里,可以看到

这里是按照发布时间排列的,往下拉可以找到已经发布的各个版本,我们找到2.7.14,这个是比较重要的一个版本

点击这里的Python-2.7.14.tgz可以直接下载安装包文件,也可以使用wget来直接下载,如果需要安装的服务器无法直接访问外网,可以使用下载安装包文件的方式,如果可以访问外部推荐使用wget方式。

wget https://www.python.org/ftp/python/Python-2.7.14.tgz

无论用哪种方式,下载到安装包之后都会得到Python-2.7.14.tgz这个安装文件

2、解压配置

解压安装文件

tar -zvf Python-2.7.14.tgz  

得到 Python-2.7.14文件夹

cd Python-2.7.14

./configure --prefix=/usr/local/python2.7

执行之后提示是这样

[root@node2 Python-2.7.14]# ./configure --prefix=/usr/local/python2.7 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... 32-bit 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 `/opt/package/python_lib/Python-2.7.14': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details 

提示:no acceptable C compiler found in $PATH

于是赶紧测试下gcc果然这个不存在,可能是虚拟机在安装CentsOS时没有选择安装GCC

[root@node2 Python-2.7.14]# gcc -bash: gcc: command not found [root@node2 Python-2.7.14]# yum -y install gcc 

执行yum -y install gcc安装了gcc ,重新执行./configure --prefix=/usr/local/python2.7可以正常安装python

执行make

执行make install

然后进入/usr/local/python2.7/bin,这个目录的内容如下:

[root@node2 bin]# ll 总用量 6164 -rwxr-xr-x. 1 root root 111 11月 9 19:24 2to3 -rwxr-xr-x. 1 root root 109 11月 9 19:24 idle -rwxr-xr-x. 1 root root 94 11月 9 19:24 pydoc lrwxrwxrwx. 1 root root 7 11月 9 19:27 python -> python2 lrwxrwxrwx. 1 root root 9 11月 9 19:27 python2 -> python2.7 -rwxr-xr-x. 1 root root 6273995 11月 9 19:24 python2.7 -rwxr-xr-x. 1 root root 1697 11月 9 19:27 python2.7-config lrwxrwxrwx. 1 root root 16 11月 9 19:27 python2-config -> python2.7-config lrwxrwxrwx. 1 root root 14 11月 9 19:27 python-config -> python2-config -rwxr-xr-x. 1 root root 18557 11月 9 19:24 smtpd.py [root@node2 bin]#             
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表