1.下載python3.6,下載目錄:/usr/local/srcpython
cd /usr/local/srclinux
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xzsql
2.解壓Python-3.6.1.tar.xzvim
xz -d Python-3.6.1.tar.xzcentos
tar -xf Python-3.6.1.tarpython2.7
3.進入解壓好的目錄Python-3.6.1,編譯安裝python3.6,安裝目錄:/usr/local/python3scrapy
mkdir /usr/local/python3url
cd Python-3.6.1centos7
./configure --prefix=/usr/local/python3.net
make && make install
到此python3安裝完畢!
4.讓系統默認使用python3,由於linux下自帶的是python2版本
cd /usr/bin
rm -rf python
ln -s /usr/local/python3/bin/python3 /usr/bin/python
5.修改yum文件,由於yum使用python2
vim /usr/bin/yum
把文件頭部的#!/usr/bin/python改爲#!/usr/bin/python2.7保存退出便可
修改/usr/libexec/urlgrabber-ext-down文件
vim /usr/libexec/urlgrabber-ext-down
把文件頭部的#!/usr/bin/python改爲#!/usr/bin/python2.7保存退出便可
6.配置pip3,由於系統默認的仍是pip
rm -rf /usr/bin/pip3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
7.解決centos下 No module named '_sqlite3',切換到Python3的下載目錄,安裝sqlite-devel,再從新編譯安裝一下python3便可
yum install sqlite-devel
cd /usr/local/src/Python-3.6.1
./configure --prefix=/usr/local/python3
make && make install