Linux CentOS7 to install python3

  • 2020-07-21 08:59:11
  • OfStack

Under CentOS7, the default installation is python2.7. Let me show you how to install python3:

1. First install es6EN3.6 dependencies that may be used


# yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel zlib-devel

2, download python source package, address for https: / / www python. org/downloads source /, and then through xftp upload, or directly use wget command, wget https: / / www python. org ftp python / 3.6.1 track/Python - 3.6.1. tgz downloaded to the local


# tar -zxvf Python-3.6.1.tgz
# cd Python-3.6.1/

3. Install python3.6 to /usr/local


# ./configure --prefix=/usr/local/ 
# make 
# make altinstall

4. Change /usr/bin/python links


# cd /usr/bin 
# mv python python.backup 
# ln -s /usr/local/bin/python3.6 /usr/bin/python 
# ln -s /usr/local/bin/python3.6 /usr/bin/python3 
# rm -rf /usr/bin/python2 
# ln -s /usr/bin/python2.7 /usr/bin/python2 

5. Change the python dependency of the yum script


# cd /usr/bin 
# ll yum* 

There are the following documents:


-rwxr-xr-x 1 root root 802 Jan 2 17:53 yum 
-rwxr-xr-x 1 root root 9374 Jan 2 17:53 yum-builddep 
-rwxr-xr-x 1 root root 8091 Jan 2 17:53 yum-config-manager 
-rwxr-xr-x 1 root root 7610 Jan 2 17:53 yum-debug-dump 
-rwxr-xr-x 1 root root 7904 Jan 2 17:54 yum-debug-restore 
-rwxr-xr-x 1 root root 10906 Jan 2 17:54 yumdownloader 
-rwxr-xr-x 1 root root 11032 Jan 2 17:54 yum-groups-manager 

Modify the above file header: #!/usr/bin/python Instead of #!/usr/bin/python2

You can install 1 tree under test 1


# yum -y install tree

If the following error occurs: File "/usr/libexec/ ES62en-ES63en-ES64en", line 28


vim /usr/libexec/urlgrabber-ext-down 

Change /usr/bin/python to /usr/bin/python2

In this way, yum will not report errors when installing the software, and the default installation is python3. When you type python, you will enter the interface python3. If you want to enter python2, you can enter python2.

conclusion

Above is the site to introduce Linux CentOS7 under the installation of python3 method, I hope to help you, if you have any questions welcome to leave a message, this site will reply you in time!


Related articles: