- 安装前准备(准备编译环境)
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel gcc-c++ gcc -y
- 获取Python3.6源码
#获取源码
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
#安装xz
yum install xz -y
#解压
tar -xvf Python-3.6.3.tar.xz -C /usr/local/src/
- 安装Python3.6
#进入源码目录
cd /usr/local/src/Python-3.6.3/
#指定安装目录
./configure --prefix=/usr/local/python3
#编译安装
#make -j 4 是让make最多允许4个编译命令同时执行,这样可以更有效的利用CPU资源
make -j 4 && make install
#做软链接,让命令python和pip随处可用
ln -s /usr/local/python3/bin/python3.6 /usr/local/bin/python
ln -s /usr/local/python3/bin/pip3.6 /usr/local/bin/pip
#升级pip到最新版本
pip install --upgrade pip
- 安装Python包
#requests包
pip install requests
#pymysql包
pip install pymysql