pip install virtualenv
virtualenv venv
virtualenv -p /usr/bin/python2.7 venv
在默认状况下,全部安装在系统范围内的包对于virtualenv是可见的。 这意味着若是你将simplejson安装在您的系统Python目录中,它会自动提供给全部的virtualenvs使用。 这种行为能够被更改,在建立virtualenv时增长 --no-site-packages 选项的virtualenv就不会读取系统包python
virtualenv venv --no-site-packages
source venv/bin/activate
deactivate
因为virtualenv用起来有点麻烦,wrapper对它进行了封装,让它更好用,最终咱们使用wrapper提供的命令,可是实际工做都是virtualenv作的react
使用管理员权限执行linux
# pip install virtualenv virtualenvwrapper
if [ -f /usr/local/python/bin/virtualenvwrapper.sh ]; then #虚拟环境的总仓库 export WORKON_HOME=$HOME/VenvRepo #指定python的版本 export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.5 #执行脚本,不一样安装的python的路径有能够不一样,能够使用which python查看 source /usr/local/python/bin/virtualenvwrapper.sh fi
而后将下面的命令运行一次:json
linux环境执行:centos
source ~/.bashrc
执行成功会有以下输出[centos环境为例]:bash
[liuyuantao@localhost ~]$ source ~/.bashrc virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/premkproject virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/postmkproject virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/initialize virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/premkvirtualenv virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/postmkvirtualenv virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/prermvirtualenv virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/postrmvirtualenv virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/predeactivate virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/postdeactivate virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/preactivate virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/postactivate virtualenvwrapper.user_scripts creating /home/liuyuantao/Develop/venv-repo/get_env_details [liuyuantao@localhost ~]$
mkvirtualenv nowamagic_venv #新建虚拟空间 workon nowamagic_venv #激活并使用虚拟空间 deactivate #退出虚拟空间 rmvirtualenv nowamagic_venv #删除虚拟空间
workon 切换到环境 deactivate 注销当前环境 lsvirtualenv 列出全部环境 rmvirtualenv 删除环境 cpvirtualenv 复制环境 cdsitepackages cd到当前环境的site-packages目录 lssitepackages 列出当前环境中site-packages内容 setvirtualenvproject 绑定现存的项目和环境 wipeenv 清除环境内全部第三方包