1、安装python3.6.5依赖环境
注:python3.7.4需要安装:yum install libffi-devel -y
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y cd /usr/local/src
2、下载并安装python3.6.5
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz tar -xzf Python-3.6.5.tgz cd Python-3.6.5 ./configure --prefix=/usr/local/python3 make && make altinstall
3、创建python3软链
mv /usr/bin/python /usr/bin/python.bk ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
4、解决yum不可用问题
vi /usr/bin/yum vi /usr/libexec/urlgrabber-ext-down 将首行python改为python2.7
5、更换pip源
mkdir ~/.pip cd ~/.pip vim pip.conf [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host=mirrors.aliyun.com
如下也行
[global]
timeout = 10
index-url = http://mirrors.aliyun.com/pypi/simple/
extra-index-url= http://pypi.douban.com/simple/
[install]
trusted-host=
mirrors.aliyun.com
pypi.douban.com
国内镜像汇总
http://pypi.douban.com/ 豆瓣 http://pypi.hustunique.com/ 华中理工大学 http://pypi.sdutlinux.org/ 山东理工大学 http://pypi.mirrors.ustc.edu.cn/ 中国科学技术大学 http://mirrors.aliyun.com/pypi/simple/ 阿里云 https://pypi.tuna.tsinghua.edu.cn/simple/ 清华大学View Code
6、pip升级及安装virtualenvwrapper
pip install --upgrade pip pip install virtualenvwrapper ln -s /usr/local/python3/bin/virtualenv /usr/local/bin/
7、使用非root用户添加启动脚本
vim ~/.bashrc 末尾加入 if [ `id -u` != ‘0‘ ]; then export VIRTUALENV_USE_DISTRIBUTE=1 # <-- Always use pip/distribute export WORKON_HOME=$HOME/.virtualenvs # <-- Where all virtualenvs will be stored source /usr/local/python3/bin/virtualenvwrapper.sh export PIP_VIRTUALENV_BASE=$WORKON_HOME export PIP_RESPECT_VIRTUALENV=true fi
8、virtualenvwrapper使用
创建并进入env环境 mkvirtualenv -p python3 env36 mkvirtualenv -p python2 env27 退出env deactivate 进入env workon env36/env27 删除env rmvirtualenv env27