Install Python under Linux Centos7

Source: Internet
Author: User

1. See if Python is already installed

CENTOS7 is installed by default python2.7.5 because some commands use it like Yum it uses python2.7.5.

Use the PYTHON-V command to see if Python is installed:

Then take a look at the location of the Python executable file:

Go to the Bin directory:

You can see the executable file Python pointing to Python2,python2 and pointing to python2.7, which means that the Python command executes the system preinstalled Python2.7.

to install another version of Python first perform the MV Python python.bak command to back up the python file .

2. Install the new version of Python

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

Download the tgz package and you're ready. In fact, the following 2 packages can be used in one
Python-3.5.1.tgz (This is not a compiled thing, can not be extracted directly after use)
PYTHON-3.5.1.TAR.XZ (This is the source of Pthon)

The downloaded tgz package is uploaded to the Linux server.

or execute the wget command to download directly 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 under this directory and goes to the folder to perform the compilation installation.

execute the./configure--prefix=/usr/local/python/python3 command: After the/configure command is complete, create a file creating Makefile, The following make command is used to install the program into the directory we specify after you use the Do install.

Configure is an executable script that has many options for using commands under the source path to be installed./configure–help output A detailed list of options.

Where the--prefix option is the path of the configuration installation, if this option is not configured, the executable file is placed by default in/usr/local/bin after installation, and the library file is
In/usr/local/lib, the configuration file is placed by default in/usr/local/etc, and other resource files are placed in/usr/local/share, which is more messy.

If you configure--prefix, such as:
./configure--prefix=/usr/local/test
All resource files can be placed in the/usr/local/test path without clutter.
Another benefit of using the-PREFIX option is uninstalling the software or porting the software. When one of the installed software is no longer needed, simply delete the installation directory,
You can uninstall the software cleanly; the porting software simply copies the entire directory to another machine (the same operating system).

Of course, to uninstall the program, you can also use the original make directory once made uninstall, but only if the make file specified uninstall.

Then execute the make, make install command.

After successful installation, go to the Python3 folder to see the Python executable directory, the Lib directory and other related directories.

Execute the ln-s/usr/local/python/python3/bin/python3/usr/bin/python command to create a soft connection. Perform python-v to see if the Python installation was successful.

Installation succeeded:

3. Modifying the Yum configuration file

Because Yum uses python2, it may not work properly after replacing with Python3, and continue to use this python2.7.5

Therefore, the Yum configuration file (Vi/usr/bin/yum) is modified.

Change the #!/usr/bin/python of the file head to #!/usr/bin/python2.7 save exit.

Because Yum uses python2, it may not work properly after replacing with Python3, and continuing with this python2.7.5 modifies the Yum configuration file (Vi/usr/bin/yum). Change the #!/usr/bin/python of the file head to #!/usr/bin/python2.7 save exit

Install Python under Linux Centos7

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.