Python第五十一天 python2升级为python3

【自取】最近整理的,有需要可以领取学习:

Python第五十一天 python2升级为python3

由于公司所使用的生产环境系统是Centos7,因此本文在Centos7系统的基础上,阐述了将python2升级为python3的方法。

[En]

The production environment system used by the company is centos7, so based on the centos7 system, this paper explains the method of upgrading python2 to python3.

centos7系统默认已经安装了python2.7,但是python2的生命周期到2020年1月1日就会终结,在这个时间点之后出现的任何问题都不会再维护

因此,将已有的用python2开发的系统升级到python3已是当务之急。

[En]

Therefore, it is urgent to upgrade the existing system developed with python2 to python3.

正式文件描述如下

[En]

The official document is described as follows

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.

因此,我们开始升级系统的python版本,这非常简单。

[En]

So, we started to upgrade the python version of the system, which is very simple.

  1. 安装python依赖包,主要是gcc编译环境,zlib解压缩包等

  2. 使用源码方式编译安装python3,必须执行编译安装,否则在安装 Python 库依赖时会有麻烦

  3. 测试安装第三方包,python3的源码包里已经包含pip包管理工具,不需要再额外安装,也就是不需要再yum install -y python-pip

如果上述三个步骤中没有错误,则相当于成功升级。现在,系统中既有python2,也有python3。

[En]

If there are no errors in the above three steps, it will be equivalent to a successful upgrade. Now there are both python2 and python3 in the system.

有朋友会问,python2和python3并存,那么如何调用python3,如何调用python2,依赖python2的系统软件是否还可以使用,比如yum

[En]

Some friends will ask, python2 and python3 coexist, then how to call python3, how to call python2, whether the system software that depends on python2 can still be used, such as yum

事实上,安装了python3后,对系统原有的python2环境没有影响,依赖python2的系统软件也可以正常使用。

[En]

In fact, after installing python3, it has no effect on the original python2 environment of the system, and the system software that depends on python2 can also be used normally.

通过查看/usr/bin路径下的python2可执行文件,我们知道系统安装后,默认情况下已经存在/usr/bin/python2、/usr/bin/python2和/usr/bin/python2.7三个python2可执行文件。

[En]

By looking at the python executable file under the / usr/bin path, we know that after the system is installed, three python2 executable files, such as / usr/bin/python, / usr/bin/python2 and / usr/bin/python2.7, already exist by default.

只要您不管它们,就不会对python2环境产生任何影响,然后在安装python3之后,创建一个软链接/usr/bin/python3->/usr/local/bin/python3

[En]

As long as you leave them alone, there will be no effect on the python2 environment, and then after installing python3, you make a soft link, / usr/bin/python3-> / usr/local/bin/python3

如果以后需要使用python3执行该脚本,只需

[En]

If you need to execute the script with python3 in the future, you only need to

要使用pip安装第三方的python3包,您只需

[En]

To install a third-party package of python3 with pip, you only need to

其他命令行参数的语法与python2相同。升级巨蟒3就是这么简单。

[En]

Other command line parameters have the same syntax as python2. Upgrading python3 is as simple as that.

如有不对的地方,欢迎大家拍砖o(∩_∩)o

本文版权归作者所有,未经作者同意不得转载。

Original: https://www.cnblogs.com/lyhabc/p/12116424.html
Author: 桦仔
Title: Python第五十一天 python2升级为python3

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/6360/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

发表回复

登录后才能评论
免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部