When upgrading the Python version, you must not uninstall Python 2.4, install python2.7, there will be endless trouble, conservative way
is to install the python2.7 source package 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 of the Python pack
# 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's default Python points to python2.7
Normally, the system's default pointing Python is still 2.4.3, even after the python2.7 installation is successful
How do I get the system's default Python to point 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 connections
If it is the default installation path, use the following command
# ln-s/usr/local/bin/python2.7/usr/bin/python
Verify the Python point is successful
# python-v
Note 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 also need to add/usr/local/python2.7/bin to the $path variable
1. Edit/etc/profile file (Permanent entry)
Locate the export PATH USER LOGNAME MAIL HOSTNAME histsize Histcontrol this line above add
Path= $PATH:/usr/local/python2.7/bin
Reinitialize the file so that the file takes effect immediately
Source/etc/profile or. /etc/profile
2, in the user directory in the ~/.bash_profile file to add variables to the single user effective (permanent)
3. Use [Export path= $PATH:/usr/local/python2.7/bin] To define a variable directly under the command line of the shell, which is valid only under the current shell (bash) or its child shell (bash). The shell shuts down, and the variable becomes invalid (temporary)
Fix a 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 displayed in the first row to!#/usr/bin/python2.4
If Python does not work, it is likely to be missing the appropriate library, you need to go to your cross-compilation environment to copy the corresponding library files.
If the following error message appears, you are not setting the Python environment variable
1
2
|
Could platform dependent libraries <exec_prefix>
consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] |
Then you need to set the Pythonhome, if the following error occurs
' Import site Faild '
Then you need to set the Pythonpath.
It is best to add the following statement to the profile file in your file system's etc directory
1
2
3
|
Export pythonhome=/usr/lib/python2.6
export pythonpath=.: $PYTHONHOME: $PYTHONHOME/site-packages
Export Path= $PATH: $PYTHONHOME: $PYTHONPATH |