一、安裝python3.6.5依賴環境python
注:python3.7.4須要安裝:yum install libffi-devel -y linux
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
二、下載並安裝python3.6.5sql
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
三、建立python3軟鏈vim
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
四、解決yum不可用問題bash
vi /usr/bin/yum vi /usr/libexec/urlgrabber-ext-down 將首行python改成python2.7
五、更換pip源app
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.comide
國內鏡像彙總阿里雲
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/ 清華大學
六、pip升級及安裝virtualenvwrapperurl
pip install --upgrade pip pip install virtualenvwrapper ln -s /usr/local/python3/bin/virtualenv /usr/local/bin/
七、使用非root用戶添加啓動腳本spa
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
八、virtualenvwrapper使用
建立並進入env環境 mkvirtualenv -p python3 env36 mkvirtualenv -p python2 env27 退出env deactivate 進入env workon env36/env27 刪除env rmvirtualenv env27