CentOS安裝python3

步驟詳情

一、CentOS安裝Python的依賴包

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
.
.python

二、下載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
.
.sql

三、把#! /usr/bin/python修改成#! /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
.
.shell

四、把/usr/bin/下的python2替換成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
.
.centos

寫成shell腳本執行

#一、CentOS安裝Python的依賴包
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

#二、下載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

#三、把#! /usr/bin/python修改成#! /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

#四、把/usr/bin/下的python2替換成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
相關文章
相關標籤/搜索