Why do you need to set the WORKON_HOME environment variable?

一个人想着一个人 提交于 2021-02-06 03:53:55

问题


I haven't used my python/virtual environments in a while, but I do have virtualenvironment wrapper installed also.

My question is, in the doc page it says to do this:

export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv env1

I simply did this at my prompt:

source /usr/local/bin/virutalenvwrapper.sh

And now I can list and select an environment by doing:

>workon

>workon envtest1

My question is, since this works for me, I'm confused why I should be creating an environmental variable WORKON_HOME and point it to the ~/Envs folder? What does that do and how come mine works fine w/o it? I don't have that /Envs folder either (I know the script creates it).

Reference: http://virtualenvwrapper.readthedocs.org/en/latest/


回答1:


If WORKON_HOME is not set, your default virtualenv folder will be set to ~/.virtualenvs
(see virtualenvwrapper.sh l.118)

You will also use WORKON_HOME to specify to pip which folder to use (export PIP_VIRTUALENV_BASE=$WORKON_HOME)

source : virtualenvwrapper.readthedocs.org : Tying to pip’s virtualenv support




回答2:


I'm confused why I should be creating an environmental variable WORKON_HOME and point it to the ~/Envs folder?

It's optional. You're confused (like I was) because the documentation is confusing.

What does that do and how come mine works fine w/o it?

It tells virtualenvwrapper which folder to search for Python environments. The command workon searches the path WORKON_HOME if it's defined, or ~/.virtualenvs if it's not, which is why it works by default.

A use case for defining a different WORKON_HOME directory would be if you have different environments you want to available to virtualenvwrapper. For example, if you save virtual env backups to a different folder or have multiple users who want to maintain their own environments.



来源:https://stackoverflow.com/questions/13787566/why-do-you-need-to-set-the-workon-home-environment-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!