简体   繁体   English

Virtualenv“。 venv / bin /激活“vs”源venv / bin /激活“

[英]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: 从阅读教程,我读到有两种方法来激活虚拟环境:

  1. . venv/bin/activate

  2. 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

The . . command is essentially an alias for the source . 命令本质上是source的别名。 They both execute a given script in the current shell without forking a new shell. 它们都在当前shell中执行给定的脚本而不需要新的shell。

Here are some nice examples. 是一些很好的例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 子进程已打开(“源venv / bin / activate”),没有这样的文件? - subprocess open ('source venv/bin/activate'),no such file? 之间的差异。 venv / bin / activate和./venv/bin/activate - Difference Between . venv/bin/activate and ./venv/bin/activate 配置 virtualenv 内容路径而不是 .venv/local/bin/activate - Configure virtualenv content path instead of .venv/local/bin/activate 源/ bin / activate激活系统解释器而不是venv一个 - source /bin/activate activates the system interpreter not the venv one 如何在 Windows 上运行它,因为它需要“source venv/bin/activate”和“flask run” - how to run this on Windows as it needs "source venv/bin/activate" and "flask run" 如何在 mac 上的 vscode 中自动加载 venv/bin/activate - How to autoload venv/bin/activate in vscode on mac bash:venv/bin/activate:没有这样的文件或目录 - bash: venv/bin/activate: No such file or directory 无法在 windows 7 中激活 virtualenv venv - unable to activate virtualenv venv in windows 7 当我输入 source env/bin/activate 时如何在 vs 代码编辑器中激活 virtualenv 它没有激活 - how to activate virtualenv in vs code editor when i type source env/bin/activate it does not activate bash: /python/run/venv/bin/activate: 没有那个文件或目录 - bash: /python/run/venv/bin/activate: No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM