CentOS 7.2 Installation python3.6, compatible with the original 2.7

Source: Internet
Author: User
Tags install openssl readline

Long ago thought to write a blog, because do a lot of things, always remember, can write down, it is a diary.


This time I want to install python3.6 in my centos7 and be compatible with the original 2.7.

1. View the original version of Python

[[email protected] ~]# python

Python 2.7.5 (Default, Nov 20 2015, 02:00:19)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2

Type "Help", "copyright", "credits" or "license" for more information.

>>>

The original version is 2.7.5, I am now ready to install a 3.6 version, and install the back note a problem, because the CentOS Yum tool uses Python is 2.7, need to pay attention to

2, download the installation package, 工欲善其事 its prerequisite, no installation package, paddle

Python's installation package can be downloaded to Python's website (Https://www.python.org/ftp/python)

Because my environment is the CENTOS7 in VM VMS above windows, I don't want to download them locally. So just download it to CentOS using wget.

(https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz)

[Email protected] ~]# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

-bash:wget: Command not found

[email protected] ~]# Yum install wget

Loaded plugins: Fastestmirror

Base | 3.6 KB 00:00

......................

has been installed:

Wget.x86_64 0:1.14-15.el7_4.1

Complete!

[Email protected] ~]# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

............................................

Connecting www.python.org (www.python.org) |151.101.72.223|:443 ... is connected.

An HTTP request has been made and is waiting for a response ... OK

Length: 22673115 (22M) [Application/octet-stream]

Saving to: "Python-3.6.3.tgz"

0% [] 183,323 2.05kb/s remaining 3h 17m

After the download is complete, unzip the file inside the package

[[email protected] ~]# ls

Anaconda-ks.cfg python-3.6.3.tgz

[Email protected] ~]# TAR-ZXVF python-3.6.3.tgz

python-3.6.3/

python-3.6.3/doc/

................................

3, with the installed package, we will solve a Linux system installation software must be a step, that is to install some necessary dependency packages.

Depend on this kind of thing, not to say, I can only install something that may need to

[email protected] ~]# Yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

...............

has been installed:

bzip2-devel.x86_64 0:1.0.6-13.el7 expat-devel.x86_64 0:2.1.0-10.el7_3

gdbm-devel.x86_64 0:1.10-8.el7 openssl-devel.x86_64 1:1.0.2k-8.el7

readline-devel.x86_64 0:6.2-10.el7 sqlite-devel.x86_64 0:3.7.17-8.el7

......................

Complete!

4, install the dependency package, you can start to compile and install Python

[[email protected] python-3.6.3]#./configure--prefix=/usr/local/python3;make;make Install

Checking build system Type ... X86_64-pc-linux-gnu

Checking host system Type ... X86_64-pc-linux-gnu

..........................

Checking for cl.exe ... no

Configure:error:in '/root/python-3.6.3 ':

Configure:error:no acceptable C compiler found in $PATH

See ' Config.log ' for more details

Make: * * does not specify the target and cannot find the makefile. Stop it.

Make: * * * There are no rules to create the target "install". Stop it.

[Email protected] python-3.6.3]#

This error requires GCC to be installed to resolve

[[email protected] python-3.6.3]# Yum install gcc

.....................................

has been installed:

Gcc.x86_64 0:4.8.5-16.EL7

..................

Complete!

Install GCC, then compile and install Python

[[email protected] python-3.6.3]#./configure--prefix=/usr/local/python3;make;make Install

......................

Collecting Setuptools

Collecting Pip

Installing collected Packages:setuptools, Pip

Successfully installed pip-9.0.1 setuptools-28.8.0

This will be installed.

5, modify the original Python point 2.7 is 3.5, and modify the Yum configuration

[Email protected] bin]# ll/usr/bin/py*

-rwxr-xr-x. 1 root root 78 November 2015/usr/bin/pydoc

lrwxrwxrwx. 1 root root 7 October 19:00/usr/bin/python-Python2

lrwxrwxrwx. 1 root root 9 October 19:00/usr/bin/python2-python2.7

-rwxr-xr-x. 1 root root 7136 November 2015/usr/bin/python2.7

Here /usr/bin/python-Python2 is

The original Python uses the /usr/bin/python2.7 version, and we're going to change it to a 3.6 version.

First of all, the original backup, or the problem to fix up trouble, after the backup can be Python3 soft connected to the /usr/bin/ directory

lrwxrwxrwx. 1 root root 7 October 19:00/usr/bin/python-Python2

lrwxrwxrwx. 1 root root 9 October 19:00/usr/bin/python2-python2.7

-rwxr-xr-x. 1 root root 7136 November 2015/usr/bin/python2.7

[Email protected] bin]# Mv/usr/bin/python/usr/bin/python.bak

[Email protected] bin]# ll/usr/bin/py*

-rwxr-xr-x. 1 root root 78 November 2015/usr/bin/pydoc

lrwxrwxrwx. 1 root root 9 October 19:00/usr/bin/python2-python2.7

-rwxr-xr-x. 1 root root 7136 November 2015/usr/bin/python2.7

lrwxrwxrwx. 1 root root 7 October 19:00/usr/bin/python.bak-Python2

[Email protected] bin]# ln-s/usr/local/python3/bin/python3/usr/bin/python

Then test what version of Python the current environment uses

[[email protected] bin]# python

Python 3.6.3 (Default, Nov 9 2017, 00:02:58)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on Linux

Type "Help", "copyright", "credits" or "license" for more information.

>>>

We're looking at the 3.6 version of the outfit, and then we're going to change the Yum configuration file.

[Email protected] bin]# Vi/usr/bin/yum

#!/usr/bin/python

Import Sys

Try

Import Yum

Except Importerror:

Print >> Sys.stderr, "" "\

There was a problem importing one of the Python modules

Required to run Yum. The error leading to this problem was:

%s

The above #!/usr/bin/python needs to be modified to #!/usr/bin/python2.7, after the modification using Yum test the Yum tool is normal, modified using Yum, found an error:

Downloading packages:

File "/usr/libexec/urlgrabber-ext-down", line 28

Except OSError, E:

^

Syntaxerror:invalid syntax

Exiting because of user cancellation

Looking at the/usr/libexec/urlgrabber-ext-down file, we found that there are also Python parameters, the same modified

[Email protected] bin]# Cat/usr/libexec/urlgrabber-ext-down

#! /usr/bin/python

# A very simple external downloader

# Copyright 2011-2012 Zdenek Pavlas

The above #!/usr/bin/python needs to be modified to #!/usr/bin/python2.7, modified to use Yum again test, normal

[[email protected] bin]# Yum install zip

.......................................

has been installed:

Zip.x86_64 0:3.0-11.EL7

Complete!

OK, check the system for Python2 and 3 coexistence

[[email protected] bin]# python

Python 3.6.3 (Default, Nov 9 2017, 00:02:58)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on Linux

Type "Help", "copyright", "credits" or "license" for more information.

>>> quit ()

[Email protected] bin]# python2.7

Python 2.7.5 (Default, Nov 20 2015, 02:00:19)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2

Type "Help", "copyright", "credits" or "license" for more information.

>>> quit ()

OK, my CENTOS7 installation python3.6 even if it's done.


This article is from the "All-up" blog, be sure to keep this source http://zhenghong.blog.51cto.com/1676992/1979991

CentOS 7.2 Installation python3.6, compatible with the original 2.7

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.