Home > System Tutorial > LINUX > body text

Install python3 under Linux CentOS7

WBOY
Release: 2024-04-18 12:20:01
forward
366 people have browsed it

在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
Copy after login

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/
Copy after login

3. Install python3.6 into the /usr/local directory

# ./configure --prefix=/usr/local/
# make
# make altinstall
Copy after login

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
Copy after login

5. Change the python dependency of the yum script

# cd /usr/bin
# ll yum*
Copy after login

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
Copy after login

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

You can install a tree to test it

# yum -y install tree
Copy after login

If the following error occurs: File “/usr/libexec/urlgrabber-ext-down”, line 28

vim /usr/libexec/urlgrabber-ext-down
Copy after login

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!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!