虚拟环境".venv/bin/激活"vs “源 venv/bin/activate" [英] Virtualenv ". venv/bin/activate" vs "source venv/bin/activate"

查看:59
本文介绍了虚拟环境".venv/bin/激活"vs “源 venv/bin/activate"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我创建了一个名为 venv (virtualenv venv) 的 virtualenv

lets say i created a virtualenv called venv (virtualenv venv)

从阅读教程中,我了解到有两种方法可以激活虚拟环境:

From reading tutorials, i read there are 2 ways to activate virtual env:

  1. <代码>.venv/bin/activate

源 venv/bin/activate

我认为他们都完成了同样的事情,但我不明白发生了什么.

I think they both accomplish the same thing, but i dont understand whats going on.

同样对于数字 1,不是."只是指当前文件夹?但如果我只输入venv/bin/activate"而没有.",它就不起作用

Also for number 1, doesnt the "." just mean the current folder? but it doesnt work if i just type in "venv/bin/activate" without the "."

任何帮助都会很棒!

推荐答案

.source 做的完全一样,唯一的区别是 source 更具可读性,可能并非在所有 shell 中都可用.

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

该命令在当前 shell 中运行脚本的内容,这在 activate 的情况下很重要,因为脚本所做的事情之一是导出和修改您的环境变量当前外壳.

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.

如果您使用 ./path/to/activate 运行它,脚本将在子 shell 中运行,并且一旦脚本完成并且子 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.

同样对于数字 1,不是."只是指当前文件夹?

. 根据上下文具有不同的含义.当用作(或部分)路径时,它仅表示当前文件夹".

. has a different meaning depending on the context. It only means "current folder" when used as (or part of) a path.

来自 http://en.wikipedia.org/wiki/Dot_%28Unix%29:

不要将 dot 命令与 dot 文件混淆,后者是带点前缀的隐藏文件或隐藏目录.

The dot command is not to be confused with a dot file, which is a dot-prefixed hidden file or hidden directory.

<小时>

顺便说一句,我建议你看看 virtualenvwrapper 提供了额外的包装命令,使 virtualenv 更易于使用.

使用virtualenvwrapper,只需调用:

workon YOUR_ENV

这篇关于虚拟环境".venv/bin/激活"vs “源 venv/bin/activate"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆