Linux-centos7 installing Python3 and coexistence with Python2

Source: Internet
Author: User

preparatory work

Centos7 the Python2.7,yum command that is installed by default is python2.7.

python --versionCheck to see if Python is installed.

cd $(dirname `which python`)Enter the directory where the Python executable file is located

mv python python.bakBack up a bit

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc makeInstall related Packages

Yum If failure reference: http://www.cnblogs.com/juneman/p/8594633.html

Compiling the installation

wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xzDownload the installation package

tar -xvJf  Python-3.6.5.tar.xzExtract

cd Python-3.6.5Go to Catalog

./configure prefix=/usr/local/python3  make && make installCompiling the installation

After the installation is complete, the/usr/local/directory will appear Python3

ln -s /usr/local/python3/bin/python3 /usr/bin/pythonAdd a soft link to the execution directory

python --versionShow Python3 is successful

python2 --versionView Python2 Version Information

Because Yum needs to be python2, we also need to modify the Yum configuration: the vim /usr/bin/yum first line of the #! /usr/bin/python fix changed to#! /usr/bin/python2

Similarly, the vim /usr/libexec/urlgrabber-ext-down first line of #! /usr/bin/python revision changed to#! /usr/bin/python2

By doing this, Python2 is coexisting with Python3.

Linux-centos7 installing Python3 and coexistence with Python2

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.