Slime: python2.7 and python3.5 source installation

Source: Internet
Author: User

This article consists of Ilanniweb provide sponsorship, starting in Slime Line the world

Want to get more articles, you can follow my ilanniweb

The previous few days when installing ansible in centos6.6, the Python version was not correct, resulting in a failure to install. Manual installation of Python can only be done manually, in order to no longer add this pit, special record the relevant installation process.

This article takes python2.7 and python3.5 installation as an example.

First, install the python2.7

Before we install Python, let's install the various dependent packages required for Python compilation, as follows:

Yum-y install XZ wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel

650) this.width=650; "title=" clip_image001 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image001 "src=" http://s3.51cto.com/wyfs02/M00/8B/3E/ Wkiol1hidj2ynozfaaba3rnvcvm707.png "width=" 652 "height=" 144 "/>

After the dependent package has been installed, we will download the pytho2.7 source package and carry out the related operation as follows:

wget HTTP://MIRRORS.SOHU.COM/PYTHON/2.7.12/PYTHON-2.7.12.TAR.XZ

TAR-XF PYTHON-2.7.12.TAR.XZ

CD Python-2.7.12

./configure--enable-shared--enable-loadable-sqlite-extensions--with-zlib

650) this.width=650; "title=" clip_image002 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image002 "src=" http://s3.51cto.com/wyfs02/M02/8B/3E/ Wkiol1hidj6wz8jpaabwmfd5j4a399.png "width=" 589 "height=" 337 "/>

650) this.width=650; "title=" clip_image003 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image003 "src=" http://s3.51cto.com/wyfs02/M01/8B/3E/ Wkiol1hidj-inuugaaa0to20svy506.png "width=" 643 "height=" 106 "/>

After the configuration is complete, compile and install as follows:

Make && make install

650) this.width=650; "title=" clip_image004 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image004 "src=" http://s3.51cto.com/wyfs02/M00/8B/3F/ Wkiol1hidkdrrsoxaabvjpg5tuw666.png "width=" 592 "height=" 177 "/>

If the installation does not have the correct error, the correct display is as follows:

650) this.width=650; "title=" clip_image005 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image005 "src=" http://s3.51cto.com/wyfs02/M02/8B/3F/ Wkiol1hidkhizisiaaacko0sab4483.png "width=" 373 "height="/>

Second, modify the system default Python version

CENTOS6 series The default Python version is python2.6.6, if we want to modify the default Python version of the system, we need to do the following.

Perform the following command, back up the python2.6, and then create a soft link for python2.7 as follows:

mv/usr/bin/python/usr/bin/python2.6.6

Ln-s/usr/local/bin/python2.7/usr/bin/python

At this point, we can execute the PYTHON–V command if the following error occurs:

Python:error while loading shared libraries:libpython2.7.so.1.0:cannot open Shared object file:no such file or Directo Ry

650) this.width=650; "title=" clip_image006 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image006 "src=" http://s3.51cto.com/wyfs02/M00/8B/3F/ Wkiol1hidkgbblxcaaalinrcoqo168.png "width=" 655 "height="/>

To edit the configuration file/etc/ld.so.conf add a new line of content/usr/local/lib, save the exit as follows:

Vim/etc/ld.so.conf

Include ld.so.conf.d/*.conf

/usr/local/lib

650) this.width=650; "title=" clip_image007 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image007 "src=" http://s3.51cto.com/wyfs02/M01/8B/3F/ Wkiol1hidkljoocgaaae409uogs460.png "width=" 363 "height=" 102 "/>

After the ld.so.conf file is configured, we need to execute the following command:

/sbin/ldconfig

/sbin/ldconfig-v

650) this.width=650; "title=" clip_image008 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image008 "src=" http://s3.51cto.com/wyfs02/M02/8B/3F/wKioL1hIDkbB_ Xy4aaa2cin0el8818.png "width=" 464 "height=" 175 "/>

Then execute the python–v command to view the Python version as follows:

650) this.width=650; "title=" clip_image005[1] "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image005[1] "src=" http://s3.51cto.com/wyfs02/M00/8B/3F/ Wkiol1hidkawr9jraaacko0sab4831.png "width=" 373 "height="/>

You can see that the default Python version of the system has been modified to python2.7.

Third, modify the Yum related configuration

python2.7 installation is complete, because the version may cause the Yum command to be unable to use, we need to make the relevant configuration.

We need to back up the python2.6 first and then modify the Yum configuration file. If you do not do this, executing the Yum command will prompt you that the Python version is incorrect.

650) this.width=650; "title=" clip_image009 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image009 "src=" http://s3.51cto.com/wyfs02/M02/8B/42/ Wkiom1hidkebomataaakz2nckfc134.png "width=" 552 "height=" 94 "/>

Then edit the/usr/bin/yum file and modify the first line of #!/usr/bin/python to #!/usr/bin/python2.6.6, as follows:

Vim/usr/bin/yum

#!/usr/bin/python2.6.6

650) this.width=650; "title=" clip_image010 "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" clip_image010 "src=" http://s3.51cto.com/wyfs02/M01/8B/42/ Wkiom1hidkiarbxeaaaxklzg_ec386.png "width=" 439 "height=" 163 "/>

There is no error message now executing the yum command.

Iv. python3.5 Installation Commands

In the above three chapters, we introduced the installation of python2.7, this chapter we put python3.5 installation command, do not carry out a detailed introduction.

Installation related dependencies:

Yum-y install XZ wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel

Install Python3:

wget HTTP://MIRRORS.SOHU.COM/PYTHON/3.5.2/PYTHON-3.5.2.TAR.XZ

TAR-XF PYTHON-3.5.2.TAR.XZ

CD Python-3.5.2

./configure--enable-shared--enable-loadable-sqlite-extensions--with-zlib

Make && make install

To modify the default Python version of the system:

mv/usr/bin/python/usr/bin/python2.6.6

Ln-s/usr/local/bin/python3/usr/bin/python

Vim/etc/ld.so.conf

/usr/local/lib

Include ld.so.conf.d/*.conf

/sbin/ldconfig

Python–v

To modify the Python version used by Yum:

Vim/usr/bin/yum

#!/usr/bin/python2.6.6

Slime: python2.7 and python3.5 source installation

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.