Python2 升级Python3

https://www.cnblogs.com/sandyyeh/p/9396108.html
今天发现虚拟机的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 +

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

    A+
发布日期:2019年11月15日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: