CENTOS7 installed by default python2.7.5, when you need to use Python3, you can manually download the Python source code after compiling the installation.
Python official website: www.python.org
1. Install the dependencies that Python may use
Yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
2. Download the source package
#cd/USR/LOCAL/SRC
#wget HTTPS://WWW.PYTHON.ORG/FTP/PYTHON/3.6.1/PYTHON-3.6.1.TAR.XZ
Or
#wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
These two packages are free to download any
3. Installation
Unpack the source package into the extracted Python source package directory
#tar ZXVF python-3.6.1.tgz
#cd Python-3.6.1
Compiling the installation
#./configure--prefix=/usr/local/python3
#make && make Install
4. at this point, the installation is complete
Edit/etc/profile File
Vim/etc/profile
Finally, add the following line
Path= $PATH:/usr/local/python3/bin/
Exprot PATH
Save exit
Later we want to use Python2, direct command Python2
Want to use Python3, direct command Python3
This is where python2 and python3 coexist.
5. If you want the system to perform python3 by default, do the following
#mv/usr/bin/python/usr/bin/python.bak
#ln-S/usr/local/python3/bin/python3/usr/bin/python
Because Yum makes some python2, it may not work properly after being replaced with Python3;
Modifying the Yum configuration file
Vim/usr/bin/yum
Change the first line of the head #!/usr/bin/python
#!/usr/bin/python2.7
Save to exit
CentOS 7 Installation python3.6.1