首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Windows Powershell中使用等同于"source“的命令激活虚拟环境

在Windows Powershell中使用等同于"source“的命令激活虚拟环境
EN

Stack Overflow用户
提问于 2020-11-05 17:06:26
回答 1查看 306关注 0票数 0

我需要在Windows Powershell中激活虚拟环境。但是,我正在使用它来继续我的项目,the guide告诉我使用这样的命令:

source venv-slither/bin/activate

在我的项目目录中,首先,我使用以下命令安装了virtualenv

pip3 install virtualenv

之后,我在文件夹./venv-slither中设置了一个虚拟环境:

source venv-slither/bin/activate

问题就出现在这里。每当我运行最后一个命令时,我都会在Powershell中看到以下消息:

代码语言:javascript
复制
source : The term 'source' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:2
+  source venv-slither/bin/activate
+  ~~~~~~
    + CategoryInfo          : ObjectNotFound: (source:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我读了一些指南来消除这个问题。他们建议使用.而不是source,但是这样也会出现同样的错误。何时,我的命令是:

. venv-slither/bin/activate

传达的信息是:

代码语言:javascript
复制
. : The term 'venv-slither/bin/activate' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:3
+ . venv-slither/bin/activate
+   ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (venv-slither/bin/activate:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

更重要的是,当我直接修改斜杠时:

. venv-slither\bin\activate

弹出以下消息:

代码语言:javascript
复制
. : The module 'venv-slither' could not be loaded. For more information, run 'Import-Module venv-slither'.
At line:1 char:3
+ . venv-slither\bin\activate
+   ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (venv-slither\bin\activate:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoLoadModule

我的项目目录中有这些模块:.bin, dot, findit, source。请帮助初学者使用Windows Powershell。

EN

回答 1

Stack Overflow用户

发布于 2021-05-25 22:24:21

我认为你应该这样使用,在Windows PS中:

代码语言:javascript
复制
venv-slither/Scripts/activate.ps1

使用该命令为当前用户启用必要的执行策略后:

代码语言:javascript
复制
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

为了安全起见,在您完成工作后,我将使用此命令返回到以前的策略:

代码语言:javascript
复制
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser

还有其他方法可以临时设置执行。例如,我可以通过发出以下命令来设置当前PS的会话:

代码语言:javascript
复制
powershell.exe -ExecutionPolicy RemoteSigned

* RemoteSigned或无限制,您可以参考此链接查看每种类型的策略允许或不允许使用哪些脚本的详细信息:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1

很抱歉发得太晚了,我刚刚发现了你的帖子,发现了同样的问题,测试了自己,它起作用了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64694115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档