python introduction
Alibaba cloud and Tencent cloud
View python version
[root@Tencent ~]# python Python 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
The default Python version of Alibaba cloud and Tencent cloud systems is 2.7. Since Python officially announced that Python 2 will be disabled in 2020, python will be upgraded directly
1,download python Installation package [root@Tencent ~]#wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz 2,decompression [root@Tencent ~]# tar -xf Python-3.5.0.tar.xz 3,Compilation and installation [root@Tencent ~]# cd Python-3.5.0/ [root@Tencent Python-3.5.0]# ./configure --prefix=/usr/local/python3 [root@Tencent Python-3.5.0]# make && make install 4,backups python2.7 [root@Tencent Python-3.5.0]# mv /usr/bin/python /usr/bin/python2.7.bak 5,to python3 Create a soft connection [root@Tencent Python-3.5.0]# ln -sv /usr/local/python3/bin/python3.5 /usr/bin/python ?.usr/bin/python?.-> ?.usr/local/python3/bin/python3.5? 6,See python Version and backspace key and direction key use [root@Tencent Python-3.5.0]# python Python 3.5.0 (default, Feb 11 2020, 13:26:01) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
If you find that python3 backspace and direction key cannot be used normally, please install the readline library file. Since the cloud server is used, you can configure the yum source policy for reference https://blog.51cto.com/14015577/2414577
7,install readline Library file [root@VM_0_4_centos ~]# yum install readline-devel.* -y
It is found that yum cannot be used at this time. It is necessary to modify the path of python of / usr/bin/yum and / usr / libeec / urlgrabber ext-down to the system's own version, such as / usr/bin/python2.7
8,modify yum Interpreter [root@Tencent ~]# head -n 1 /usr/bin/yum #!/usr/bin/python2.7 [root@Tencent ~]]# head -n 1 /usr/libexec/urlgrabber-ext-down #! /usr/bin/python2.7 //Install readline library file [root@Tencent ~]yum install readline-devel.* -y 9,install readline Library succeeded, reinstall compilation python [root@Tencent Python-3.5.0]# ./configure --prefix=/usr/local/python3 [root@Tencent Python-3.5.0]# make && make install 10,to python3 Create a soft connection [root@Tencent Python-3.5.0]# ln -sv /usr/local/python3/bin/python3.5 /usr/bin/python ?.usr/bin/python?.-> ?.usr/local/python3/bin/python3.5?
python backspace and direction key can be used normally
11,See python Version and backspace key and direction key use [root@Tencent Python-3.5.0]# python Python 3.5.0 (default, Feb 11 2020, 13:26:01) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
Because Yum uses Python as the interpreter, and adds alias to python3, so it doesn't need to change the interpreter of yum, directly in the
After the completion of 3-step compilation and installation, the operation will be completed. At this time, python3 can use aliases, and backspace key and direction key can be used normally. This method omits all steps after step 3.
Temporary change [root@Tencent Python-3.5.0]# alias python3=/usr/local/python3/bin/python3.5 //Permanent change [root@Tencent Python-3.5.0]#vim ~/.bashrc alias python3=/usr/local/python3/bin/python3.5 [root@Tencent Python-3.5.0]# python Python 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [root@VM_0_4_centos ~]# python3 Python 3.5.0 (default, Feb 11 2020, 14:11:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print('hello world!') hello world!