您的位置:首页 > 移动开发

Python 开发环境管理 virtualenvwrapper

2018-01-29 20:19 591 查看
安装

初次启动

虚拟环境

常用命令

virtualenvwrapper 时一个基于virtualenv之上的工具,它将所有的虚拟环境统一管理。

安装

使用pip进行安装

# whoami at iamwho in [~]
$ pip install virtualenvwrapper -i https://pypi.douban.com/simple/[/code] 

初次启动

Ubuntu自带python安装的
virtualenvwrapper


source /usr/local/bin/virtualenvwrapper.sh


miniconda或者anaconda安装的
virtualenvwrapper


source miniconda2/bin/virtualenvwrapper.sh


还可以将该命令添加到
~/.bashrc
~/.profie
等shell启动文件中,以便登陆shell后可直接使用virtualenvwrapper提供的命令。

对于virtualenvwrapper的配置:

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/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true

fi


将上面的配置添加到
~/.bashrc
的末尾或者
~/.zshrc


虚拟环境

virtualenvwrapper默认将所有的虚拟环境放在~/.virtualenvs目录下管理,

# whoami at iamwho in [~]
$ source miniconda2/bin/virtualenvwrapper.sh
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/whoami/.virtualenvs/get_env_details


可以修改环境变量WORKON_HOME来指定虚拟环境的保存目录。

常用命令

mkvirtualenv

usage:

mkvirtualenv    [-a project_path]
[-i package]
[-r requirements_file]
[virtualenv options] env_name


workon

workon env_name
Deactivate any currently activated virtualenv
and activate the named environment, triggering
any hooks in the process.

workon == lsvirtualenv
Print a list of available environments.
(See also lsvirtualenv -b)

workon (-h|--help)
Show this help message.

workon (-c|--cd) envname
After activating the environment, cd to the associated
project directory if it is set.

workon (-n|--no-cd) envname
After activating the environment, do not cd to the
associated project directory.


lsvirtualenv is equal to workon without params

deactivate 跟virtualenv的一样

rmvirtualenv

$ rmvirtualenv --help
Removing --help...
Did not find environment /home/whoami/.virtualenvs/--help to remove.


以上为常用的命令足够用,具体参数其实跟virtualenv差不多。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Python