Python2 升级Python3
今天发现虚拟机的python还是2.7.5的,就想着升级一下。最新的python已经是3.7.0了。所以我打算先升级到3.6.6(https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz)
1、查看当前python版本号
[root@localhost ~]# python -V Python 2.7.5
2、下载python3.6.6的压缩包
[root@localhost ~]# wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
3、配置编译
./configure --prefix=/usr/local/python3 --with-ssl
4、编译
make
5、安装
make install
插曲》》》》报错了:
Traceback (most recent call last): File "/root/Python-3.6.6/Lib/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/root/Python-3.6.6/Lib/runpy.py", line 85, in _run_code exec(code, run_globals) File "/root/Python-3.6.6/Lib/ensurepip/__main__.py", line 5, in <module> sys.exit(ensurepip._main()) File "/root/Python-3.6.6/Lib/ensurepip/__init__.py", line 204, in _main default_pip=args.default_pip, File "/root/Python-3.6.6/Lib/ensurepip/__init__.py", line 117, in _bootstrap return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths) File "/root/Python-3.6.6/Lib/ensurepip/__init__.py", line 27, in _run_pip import pip._internal zipimport.ZipImportError: can't decompress data; zlib not available make: *** [install] 错误 1 [root@localhost Python-3.6.6]#
缺少依赖包。安装zlib依赖:yum -y install zlib zlib-devel
6、安装成功
Looking in links: /tmp/tmp26bk5rd2 Collecting setuptools Collecting pip Installing collected packages: setuptools, pip Successfully installed pip-10.0.1 setuptools-39.0.1
7、查看以前的python信息
[root@localhost bin]# ll /usr/bin/python* lrwxrwxrwx. 1 root root 7 7月 31 22:29 /usr/bin/python -> python2 lrwxrwxrwx. 1 root root 9 7月 31 22:29 /usr/bin/python2 -> python2.7 -rwxr-xr-x. 1 root root 7216 7月 13 21:07 /usr/bin/python2.7 -rwxr-xr-x. 1 root root 1835 7月 13 21:07 /usr/bin/python2.7-config lrwxrwxrwx. 1 root root 16 7月 31 22:29 /usr/bin/python2-config -> python2.7-config lrwxrwxrwx. 1 root root 30 7月 31 23:16 /usr/bin/python3 -> /usr/local/python3/bin/python3 lrwxrwxrwx. 1 root root 14 7月 31 22:29 /usr/bin/python-config -> python2-config
可以看出以前的python 是一个软链指向python2 ,python2指向python2.7。
8、现在把python指向python3就OK了。
[root@localhost bin]# pwd
/usr/bin
[root@localhost bin]# ln -fs python3 python
9、大功告成
[root@localhost bin]# python -V Python 3.6.6