In general, the Python version that comes with the system is 2.7. python2.7 is the last version of the 2 series and has been discontinued and will be terminated shortly. You can check what version of Python the system installs by using the following command, for example, the following version is python2.7
[Email protected] opt]# python-v Python 2.7.5 [Email protected] opt]# Python3 -bash:python3: Command not found [Email protected] opt]# |
Method/Step
Here are the quick and easy steps to upgrade to Python3:
1, to the Python repository Http://www.python.org/ftp/python see the version you need to download, and then download, for example, to download python3.6.5.
[[email protected] opt]# wget https://www.python.org/ftp/python/3.6.5/ Python-3.6.5.tgz --2018-05-22 15:25:18--https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz Parsing host www.python.org (www.python.org) ... 151.101.72.223, 2a04:4e42:36::223 connecting www.python.org (www.python.org) |151.101.72.223|:443 ... connected. The has issued an HTTP request and is waiting for a response ... $ ok Length: 22994617 (22M) [Application/octet-stream] Saving to: "Python-3.6.5.tgz" 100%[=================== ===================>] 22,994,617 5.82mb/s spents 4.8s 2018-05-22 15:25:23 (4.61 MB/s)-Saved "python-3.6.5.tgz" [2299 4617/22994617]) [[email protected] opt]# ls mysql57-community-release-el7-11.noarch.rpm python-3.6.5.tgz Tidb-enterprise-tools-latest-linux-amd64 tidb-enterprise-tools-latest-linux-amd64.sha256 Tidb-enterprise-tools-latest-linux-amd64.tar.gz [[email protected] opt]# |
It is generally downloaded to the current directory. If you don't know where you downloaded it, you can find it by using the following command:
Find/-name python-3.6.5.tgz
2, in order to keep the old version 2.7, you can create a new installation path for the newer version:
Mkdir/usr/local/python3
3. Go back to the python-3.6.1.tgz directory you just downloaded and unzip the file:
TAR-XZVF python-3.6.1.tgz
Then CD into the unpacked folder Python-3.6.1, compile and install, execute the following command in turn:
./configure--prefix=/usr/local/python3
Make
Make install
4, make the new version of python3.6 effective, first back up the old Python link:
Mv/usr/bin/python/usr/bin/python2.7_old
(The default version of the system is/usr/bin/python)
Then create a new link for the Python3 that you just installed:
Ln-s/usr/local/python3/bin/python3/usr/bin/python
You can then enter the command python-v to see the newly installed version.
5.
Although the above method can install the new version properly, but it will bring other problems, such as Yum does not work properly,
You can now modify the old Python version of the first behavior backup of/usr/bin/yum:
#!/usr/bin/python2.7_old
Upgrade Python2 to Python3 under Linux