virtualenvwrapper使用

virtualenvwrapper简介

virtualenvwrapper是virtualenv的一组扩展工具.它方便了创建,删除python虚拟开发环境,使得管理多个虚拟python环境变得更容易

Features

在一个地方组织管理所有的虚拟开发环境.
封装简化了管理虚拟环境(创建,删除,复制等).
使用单一命令就可快在不同环境快速切换.
命令行下支持环境名tab补全.
支持操作配置.
丰富的插件.

安装

1
haotianfei@tianfei-opensuse:~ > sudo pip install virtualenvwrapper

将下面的初始变量添加天.bashrc中

1
2
3
export WORKON_HOME='~/.virtualenvs'
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.6
source /usr/bin/virtualenvwrapper.sh

创建一个虚拟环境

1
2
3
4
5
6
7
8
9
10
11
haotianfei@tianfei-opensuse:~ > mkvirtualenv d2be
Using base prefix '/usr'
New python executable in /home/haotianfei/.virtualenvs/d2be/bin/python3
Also creating executable in /home/haotianfei/.virtualenvs/d2be/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /home/haotianfei/.virtualenvs/d2be/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/haotianfei/.virtualenvs/d2be/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/haotianfei/.virtualenvs/d2be/bin/preactivate
virtualenvwrapper.user_scripts creating /home/haotianfei/.virtualenvs/d2be/bin/postactivate
virtualenvwrapper.user_scripts creating /home/haotianfei/.virtualenvs/d2be/bin/get_env_details

显示当前已经创建的虚拟环境

1
2
3
4
(d2be) haotianfei@tianfei-opensuse:~ > lsvirtualenv
d2be
====
d2b3

切换虚拟环境

1
(d2be) haotianfei@tianfei-opensuse:~ > workon d2be

退出

1
(d2b3) haotianfei@tianfei-opensuse:~> deactivate

删除

1
2
haotianfei@tianfei-opensuse:~> rmvirtualenv d2b3
Removing d2b3...
坚持原创技术分享,您的支持将鼓励我继续创作!