How to install python3 in CentOS7, centos7python3

Source: Internet
Author: User
Tags install openssl

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/pythonChange#!/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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.