Linux python version upgrade

Source: Internet
Author: User

Do not uninstall Python 2.4 When upgrading Python version, then install python2.7, there will be endless trouble, conservative way

is the source package that installs python2.7 directly, that is, Python two versions coexist. (because there are many programs in CentOS that rely on Python,

All the best not to try to uninstall python2.4).

Installing Python requires the GCC tool to first see if GCC is installed

# gcc-v

Install using the Yum command if not installed

# yum-y Install GCC

Download the latest installation Python package

# wget Http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz

Unpack the Package

# TAR-XZVF Python-2.7.6.tgz

Compiling the installation

#./configure--prefix=/usr/local/python2.7

# Make && make install

Establish a soft connection so that the system default Python points to python2.7

Under normal circumstances, even though the python2.7 installation succeeds, the python that the system points to by default is still 2.4. Version 3

How do you point to the system default Python to version 2.7?

# Mv/usr/bin/python/usr/bin/python.bak

# ln-s/usr/local/python2.7/bin/python2.7/usr/bin/python # Add soft Connect

If this is the default installation path, use the following command

# ln-s/usr/local/bin/python2.7/usr/bin/python

Verify that the Python point is successful

# python-v

Note that the Python Toolkit installed later, such as EASY_INSTALL,PIP, will be installed in the/usr/local/python2.7/bin directory

To use these commands directly, you need to add/usr/local/python2.7/bin to the $path variable.

1. Edit/etc/profile file (Permanent entry)

Find Export PATH USER LOGNAME MAIL HOSTNAME histsize Histcontrol this line joins

Path= $PATH:/usr/local/python2.7/bin

Reinitialize the file to make the file effective immediately

Source/etc/profile or. /etc/profile

2. Add variables to the ~/.bash_profile file in the user directory for single user (permanent)

3. Define the variable directly under the shell's command line using [Export path= $PATH:/usr/local/python2.7/bin], which is valid only under the current shell (bash) or its child shell (bash). The shell is closed and the variable is invalidated (temporary).

Fix yum that doesn't work, and if you use Yum, you'll find an error because Yum relies on 2.4.3 and now the default Python version is 2.7.6.

# Vi/usr/bin/yum

Change the!#/usr/bin/python shown in the first line to!#/usr/bin/python2.4

If Python does not work, it is likely that the corresponding library is missing, and you need to copy the corresponding library file into your cross-compilation environment.
If the following error message appears, you are not setting the Python environment variable

12
Could not find platform dependent libraries <exec_prefix> consider setting $PYTHONHOME to <p Refix>[:<exec_prefix>]

At this point you need to set Pythonhome if the following error occurs
' Import site Faild '
At this point you need to set Pythonpath.
It is best to add the following statement to the profile file in your file system's etc directory

123
Export Pythonhome=/usr/lib/python2.6export pythonpath=.: $PYTHONHOME: $PYTHONHOME/site-packagesexport path= $PATH: $ Pythonhome: $PYTHONPATH

Linux python version upgrade

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.