Home  >  Article  >  System Tutorial  >  Install python3 under Linux CentOS7

Install python3 under Linux CentOS7

WBOY
WBOYforward
2024-04-18 12:20:01391browse

在Linux CentOS7 下安装 python3

Under CentOS7, python2.7 is installed by default. Now I will teach you how to install python3:

1. First 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/downloads/source/, and then upload it through xftp, or directly use the wget command, wget https://www.python.org/ ftp/python/3.6.1/Python-3.6.1.tgz download to local

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

3. Install python3.6 into 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*

There are the following files:

-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 to #!/usr/bin/python2

You can install a tree to test it

# 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, yum will not report an error when installing the software, and the default installation is python3. When you enter python, you will enter the python3 interface. If you want to enter python2, then enter python2.

The above is the detailed content of Install python3 under Linux CentOS7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete