1.安裝必備的工具
wget:yum install wget
gcc:yum install gcc
zlib zlib-devel: yum install zlib zlib-devel -y
openssl-devel:yum install openssl-devel
2.下載python3.6.3
wget https://www.Python.org/ftp/python/3.6.3/Python-3.6.3.tgz
如果想下載其他版本只需改版本號即可
3.解壓Python
tar zxvf Python-3.6.3.tgz
將其移動到用戶文件夾
mv Python-3.6.3 ~/softwares/Python-3.6.3
4.進入Python文件夾,創建安裝目錄
cd ~/softwares/Python-3.6.3
mkdir /usr/local/python3.6.3
5.配置Python安裝位置
./configure --prefix=/usr/local/python3.6.3
./configure --with-ssl
6.編譯Python
make
7.安裝Python
make install
編譯過程中有出現”zipimport.ZipImportError: can’t decompress data; zlib not available”錯誤提示,是由於缺少包導致的,解決方法是安裝需要的包:
yum install zlib zlib-devel -y
8.備份原有python命令執行文件
mv /usr/bin/python /usr/bin/pythonbak
9.創建新的Python軟連接
ln -s /usr/local/python3.6.3/bin/python3.6 /usr/bin/python
注意路徑一定要寫對,若/usr/bin/python存在,將其刪掉再執行上面命令
10.查看Python版本
python

11.修改yum配置文件,防止yum不可用
vi /usr/bin/yum
把文件頭部的#!/usr/bin/python改成#!/usr/bin/python2.6保存退出即可。
12.pip安裝
#下載源代碼
wget --no-check-certificate https://github.com/pypa/pip/archive/9.0.1.tar.gz
tar -xf 9.0.1.tar # 解壓文件
cd pip-9.0.1
# 使用 Python 3 安裝
python3 setup.py install
創建鏈接:
sudo ln -s /usr/local/python3/bin/pip /usr/bin/pip3
pip3 install requests
參考鏈接
https://blog.csdn.net/shaobingj126/article/details/50290359
https://jingyan.baidu.com/article/cbf0e500475c042eab289362.html
