Centos7 install python3.6 to replace the default python2.7

  • Install python3.6 may use dependencies
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
  • Go to the python official website to find the download path and download it with wget
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
  • Unzip the tgz package
tar -zxvf Python-3.6.4.tgz
  • Move python to /usr/local
mv Python-3.6.4 /usr/local
  • Remove old version of python dependency
ll /usr/bin | grep python

rm -rf /usr/bin/python
  • Enter the python directory
cd /usr/local/Python-3.6.5/
  • Configuration
./configure
  • Compile make
make
  • Compile and install
make install
  • Delete the old soft link and create a new soft link to python
rm -rf /usr/bin/python

ln -s /usr/local/bin/python3.6 /usr/bin/python

python -V
  • Question answering
    yum Because of the python2 used by default, we directly overwrite the original python, which is a problem with yum.
    Therefore: if the soft link directly overwrites and replaces the 2.7.5 version, you need to modify the head environment variable line in the yum configuration file to display the bin location of the specified python2.7.5

Specific operation

Open vim /usr/bin/yum and
change the first line: #!/usr/bin/python to /usr/bin/python2.7 and
save

But when using yum, it will still be wrong, such as:
SyntaxError: invalid syntax
File “/usr/libexec/urlgrabber-ext-down”, line 28 At
this time, it is still because the environment variable line defaults to the python3 environment variable. The result is the same as above:
open the /usr/libexec/urlgrabber-ext-down file and
change #! /usr/bin/python to #! /usr/bin/python2.7

If other software has similar problems, use the same method to solve it.

Reprinted at: https://www.cnblogs.com/fixdq/p/9879285.html

Guess you like

Origin blog.csdn.net/wlc_1111/article/details/110853081
Recommended