CentOS 7 installation python3

Step Details

1, CentOS Python installation dependencies

yum groupinstall "Development tools" yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel . .

2, download the source package and compile Python3X

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz tar -zxvf Python-3.6.1.tgz cd Python-3.6.1 ./configure --prefix=/usr/local/python36 yum -y install zlib* openssl-devel make && make install . .

3, the #! / Usr / bin / python changed to #! / Usr / bin / python2

sed -i 's/#!/usr/bin/python/#!/usr/bin/python2.6/' /usr/bin/yum (可选)sed -i 's/#! /usr/bin/python/#! /usr/bin/python2/' /usr/libexec/urlgrabber-ext-down . .

4, replace python2 / usr / bin / into the python3

mv /usr/bin/python /usr/bin/pythonold cp /usr/local/python36/bin/python3.6 /usr/bin/python cp /usr/local/python36/bin/pip3 /usr/bin/pip3 . .

Written as a shell script execution

 

# . 1, the CentOS installation dependencies Python yum groupinstall "Development tools" zlib install yum -devel bzip2 -devel OpenSSL -devel ncurses -devel SQLite -devel readline -devel tk -devel gdbm -devel DB4 -devel libpcap -devel the xz -devel # 2, download Python3X source package and compile HTTPS wget : / / WWW .python .org / FTP / Python / 3.6 . . 1 / the Python -3.6 . . 1 .tgz the tar -zxvf the Python -3.6 . . 1 .tgz the Python CD -3.6 . . 1 . / Configure --prefix = / usr/ local / python36 yum -y install zlib * OpenSSL -devel the make && the make install # 3, the / usr / bin / yum file header # ! / usr / bin / Python changed to # ! / usr / bin / python2 not must be the name, anyway yum file header to specify a file python2, which can be sed python2.7 -i 'S / #! \ / usr \ / bin \ / Python / #! \ / usr \ / bin \ / python2 .6 / ' / usr / bin / yum # (optional) Sed -i ' S / \ # \! \ / usr \ / bin \ / Python / \ # \! \ / usr \ / bin \ / python2 / ' / usr / libexec / urlgrabber -ext -down # . 4, the / usr / bin Alternatively python2 / into the Music Videos to python3 / usr / bin / Python / usr/bin/pythonold cp /usr/local/python36/bin/python3.6 /usr/bin/python cp /usr/local/python36/bin/pip3 /usr/bin/pip3

Guess you like

Origin www.cnblogs.com/whale-hunter/p/11839329.html