How to install python3 in CentOS7, centos7python3
In CentOS7, python2.7 is installed by default. I will teach you how to install python3:
1. Install the dependencies that may be used by python3.6.
# yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel zlib-devel
2. Download The python source code package at https://www.python.org/ftp/python/3.6.1/python-3.6.1.tgz. download it to your local device.
# tar -zxvf Python-3.6.1.tgz# cd Python-3.6.1/
3. Install python3.6 in the/usr/local directory.
# ./configure --prefix=/usr/local/ # make # make altinstall
4. Change the/usr/bin/python Link
# 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*
The following files are available:
-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
Change#!/usr/bin/python2
You can install a tree to test the function.
# yum -y install tree
If the following error occurs: File "/usr/libexec/urlgrabber-ext-down", line 28
vim /usr/libexec/urlgrabber-ext-down
Change/usr/bin/python to/usr/bin/python2.
In this way, no errors will be reported when the yum software is installed, and python3 is installed by default. When you input python, The python3 interface will be displayed. If you want to enter python2, enter python2.
Summary
The above section describes how to install python3 in centos 7. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in time!