[英]Virtualenv “. venv/bin/activate” vs “source venv/bin/activate”
lets say i created a virtualenv called venv (virtualenv venv) 让我说我创造了一个名为venv(virtualenv venv)的virtualenv
From reading tutorials, i read there are 2 ways to activate virtual env: 从阅读教程,我读到有两种方法来激活虚拟环境:
. venv/bin/activate
source venv/bin/activate
I think they both accomplish the same thing, but i dont understand whats going on. 我认为他们都完成了同样的事情,但我不明白发生了什么。
Also for number 1, doesnt the "." 对于数字1,不是“。” just mean the current folder?
只是意味着当前的文件夹? but it doesnt work if i just type in "venv/bin/activate" without the "."
但如果我只输入“venv / bin / activate”而没有“。”,它就无法工作。
any help would be great! 任何帮助都会很棒!
.
and source
do exactly the same thing, with the only difference being that while source
is more readable, it may not be available in all shells. 和
source
做完全相同的事情,唯一的区别是虽然source
更具可读性,但它可能并非在所有shell中都可用。
The command runs the contents of the script within the current shell, and this is important in the case of activate
, because one of the things that the script does is exports and modifies environment variables within your current shell. 该命令在当前shell中运行脚本的内容,这在
activate
的情况下很重要,因为脚本执行的操作之一是导出并修改当前shell中的环境变量。
If you were to run it using ./path/to/activate
, the script will be run within a subshell and all environment variables that are set will be lost once the script completes and the subshell terminates. 如果您使用
./path/to/activate
运行它,脚本将在子shell中运行,并且一旦脚本完成并且子shell终止,所有设置的环境变量都将丢失。
Also for number 1, doesn't the "."
对于数字1,不是“。” just mean the current folder?
只是意味着当前的文件夹?
.
has a different meaning depending on the context. 具体取决于具体情况。 It only means "current folder" when used as (or part of) a path.
当用作(或部分)路径时,它仅表示“当前文件夹”。
From http://en.wikipedia.org/wiki/Dot_%28Unix%29 : 来自http://en.wikipedia.org/wiki/Dot_%28Unix%29 :
The dot command is not to be confused with a dot file, which is a dot-prefixed hidden file or hidden directory .
dot命令不要与点文件混淆, 点文件是以点为前缀的隐藏文件或隐藏目录 。
As an aside, I would suggest that you take a look at virtualenvwrapper
which provides additional wrapper commands that make virtualenv
much easier to use. virtualenvwrapper
说一句,我建议你看一下virtualenvwrapper
,它提供了额外的包装命令,使virtualenv
更容易使用。
Using virtualenvwrapper
, switching to an evironment is done simply by calling: 使用
virtualenvwrapper
,只需调用以下命令即可切换到环境:
workon YOUR_ENV
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.