基础准备
修改本地时区
cp -rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
安装epel yum源
yum -y install epel-release
安装各类依赖环境,依赖包
yum -y groupinstall "Development Tools"
yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
yum -y install zlib zlib-devel python-devel zlib-devel openssl-devel gcc mysql-devel
安装3.6.6
下载Python 3.6.6
wget -c https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
解压编译
mkdir -p /usr/local/python3
tar -xvf Python-3.6.6.tar.xz
cd Python-3.6.6/
./configure --prefix=/usr/local/python366
make && make install
创建链接到系统bin
ln -s /usr/local/python366/bin/python3 /usr/bin/python3
验证安装,打印版本
python3 -V
修改pip源为国内源,目的为 pip install 加快速度
vim /root/.pip/pip.conf
[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/
pip3配置
ln -s /usr/local/python366/bin/pip3 /usr/bin/pip3
pip3安装虚拟环境
pip3 install virtualenvwrapper
创建虚拟环境目录
mkdir /opt/venv
添加环境变量,加到文件尾部
vim /etc/profile
……
export WORKON_HOME=/opt/venv
export VIRTUALENVWRAPPER_PYTHON=/usr/local/python366/bin/python3
source /usr/local/python366/bin/virtualenvwrapper.sh
给virtualenv做个软连接
ln -sf /usr/local/python366/bin/virtualenv /bin/virtualenv
列出虚拟环境列表
workon
创建虚拟环境
mkvirtualenv noah
离开虚拟环境
deactivate
至此python和虚拟环境全部完成。