1, prepare
CentOS comes with Python, so it can be executed directly under the shell: Python
can see the corresponding printing information, but the system comes with a python version is too old, so you should recompile a new version of Python.
However, it is best not to overwrite the original system with Python, in case the system appears inexplicable problems, you can compile the new version of Python into a specified directory, so the best!
2, download a new version of Python (2.7.8)
Address: https://www.python.org/downloads/source/
Extract:
xz-d python-2.7.8.tar.xz---decompression. XZ
TAR-XVF Python-2.7.8.tar---unzip. tar
3, installation
CD Python-2.7.8
./configure--prefix=/usr/local/python27
If it is an error, please install the dependent package of the corresponding defect, and then proceed to execute the instruction!
Make && make install
Wait for the installation to complete before executing:
/usr/local/python27/bin/python
You can see the Python print out the information that shows the Python version is the new version we installed!
The script can now be connected to the/usr/bin directory so that it can be started directly in the shell and executed:
Ln-s/usr/local/python27/bin/python/usr/bin/python27
Then execute directly in the shell: python27
As you can see, the printed information is our latest version of Python installed!
3. Run a python file
To switch directories to the home directory, create a new Python folder in which a suffix named:. py
File and enter the following code:
#!/usr/bin/python27
Import Platform
Print Platform.uname ()
Then save the file to exit, add executable permissions to the file after execution:./file name
You can see the information!
At this point, complete!
centos6.4 the installation python2.7