CentOS Installation Python2.7

Source: Internet
Author: User

1. View native system and Python version
# cat /etc/redhat-release CentOS release 6.7 (Final)

View the Python version of CentOS release 6.7 (Final)

# python -VPython 2.6.6

Note that we do not disrupt the system's Python environment, because several key utility applications rely on the system's default Python 2.6.6, which can cause many unpredictable errors if the system's Python environment is broken, causing the system to be re-installed.

2. Yum Install the Developer Library set and some additional packages
# yum groupinstall "Development tools"# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
3. Download and unzip the python2.7.11 source package
# wget -c https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz# tar xf Python-2.7.11.tar.xz# cd Python-2.7.11
4. Compile and install python2.7.11
# ./configure --prefix=/usr/local# make && make altinstall

Where you ./configure --prefix= specify the installation path, according to the official documentation, if you want to install multiple Python runtimes in the same directory, use make Altinstall rather than make install

(Note: prefix is not specified, the executable file is placed by default in/usr/local/bin, the library file is placed by default in/usr/local/lib, and the configuration file is placed by default in/usr/local/etc.) Other resource files are placed in the/usr/local/share. You want to uninstall this program, either in the original make directory with the made uninstall (if the make file specified uninstall), or go to the above directory to delete the relevant files by hand.
Specify prefix, delete a folder directly is enough)

5. Create a soft link for python2.7 execution files
# ln -s /usr/local/bin/python2.7 /usr/local/bin/python

Will /usr/local/bin/python point to/usr/local/bin/python2.7

6. Detecting Python versions
# shsh-4.1# python -VPython 2.7.11sh-4.1# exitexit# pythonPython 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>>

We found that the sh version of Python that was detected under IS 2.7.11, but the terminal is still the default 2.6.6, this is because to restart the terminal to take effect, after we restart the terminal:

The Python version defaults to our new installation Python 2.7.11 , because in the environment variable path is preceded by a /usr/local/bin /usr/bin high priority:

# echo $PATH/usr/local/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.8.0_60/bin:/root/bin

or see which Python is currently in use:

# which python/usr/local/bin/python

To view the Python path:

# whereis pythonpython: /usr/bin/python2.6 /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python /usr/local/bin/python2.7-config /usr/local/bin/python2.7 /usr/local/lib/python2.7 /usr/include/python2.6 /usr/share/man/man1/python.1.gz
7. Resolving the Delete Backspace arrow key does not work with the problem

If found, under the Python command line, the Delete Backspace arrow key does not work with the problem, as follows:

# pythonPython 2.7.11 (default, Feb 24 2016, 09:50:38) [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> ex^[[D^[[D^[[C^[[C^[[C^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^[[3~^[[3~^[[3~^C

This is because no installation was caused until the python was compiled and installed readline-devel .
The solution is to install first readline-devel , then back to the source package path, re-execute the command installation, can be resolved as follows:

# yum install readline-devel# cd Python-2.7.11# make && make altinstall

To this, we completed the installation of centos6.7 under python2.7.11!
OK, Enjoy it!!!

CentOS Installation Python2.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.