Install Python and centos7python in centos 7

Source: Internet
Author: User

Install Python and centos7python in centos 7

1. Check whether Python has been installed.

Centos7 is installed with python2.7.5 by default because some commands use it, such as yum, which uses python2.7.5.

Run the python-V command to check whether Python is installed:

 

Check the location of the Python executable file:

Go to the bin directory:

You can see that the executable file python points to python2, and python2 points to python2.7, that is, the pre-installed Python2.7 of the Python Command Execution System.

To install other Python versions, run the mv python. bak command to back up the python file.

2. Install the new version of Python

Download new Python version https://www.python.org/downloads/source/

 

Download the tgz package. In fact, either of the following two packages can be used.
Python-3.5.1.tgz (this is not compiled, can not be decompressed directly use)
Python-3.5.1.tar.xz (this is pthon source code)

Upload the downloaded tgz package to the Linux server.

Or execute the wget command to directly download to the server: wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz

Decompression: tar-zxvf Python-3.5.1.tgz

After compression, the Python-3.5.1 folder appears in the directory. Go to the folder and execute compilation and installation.

Run the./configure -- prefix =/usr/local/python/python3 command .. After the/configure command is executed, create a file creating Makefile for the following make command to install the program in the specified directory after running make install.

Configure is an executable script with many options. Use the command./configure-help in the source code path to be installed to output a detailed list of options.

The -- prefix option indicates the installation path. If this option is not configured, the executable files are stored in/usr/local/bin by default.
In/usr/local/lib, the configuration file is stored in/usr/local/etc by default, and other resource files are stored in/usr/local/share, which is messy.

If -- prefix is configured, for example:
./Configure -- prefix =/usr/local/test
All resource files can be placed in the path of/usr/local/test without clutter.
Another benefit of using the-prefix option is to uninstall or port the software. When a software installation is no longer needed, you must simply delete the installation directory,
You can uninstall the software cleanly. to transplant the software, you only need to copy the entire directory to another machine (the same operating system ).

Of course, to uninstall the program, you can also use make uninstall in the original make directory, provided that the make file has specified uninstall.

Then run the make and make install commands.

After the installation is successful, go to the python3 folder to view the executable file directory, lib directory, and other related directories of Python.

Run ln-s/usr/local/python/python3/bin/python3/usr/bin/python to create a soft connection. Run python-V to check whether Python is successfully installed.

Installed successfully:

3. Modify the yum configuration file

Because yum uses python2, replacing it with python3 may not work properly. continue to use this python2.7.5

Therefore, modify the yum configuration file (vi/usr/bin/yum ).

#! /Usr/bin/python #! /Usr/bin/python2.7 save and exit.

Because yum uses python2, replacing it with python3 may not work normally. continue to use this python2.7.5 So modify the yum configuration file (vi/usr/bin/yum ). #! /Usr/bin/python #! /Usr/bin/python2.7 save and exit.

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.