我需要在Windows Powershell中激活虚拟环境。但是,我正在使用它来继续我的项目,the guide告诉我使用这样的命令:
source venv-slither/bin/activate
在我的项目目录中,首先,我使用以下命令安装了virtualenv:
pip3 install virtualenv
之后,我在文件夹./venv-slither中设置了一个虚拟环境:
source venv-slither/bin/activate
问题就出现在这里。每当我运行最后一个命令时,我都会在Powershell中看到以下消息:
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
传达的信息是:
. : 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
弹出以下消息:
. : 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。
发布于 2021-05-25 22:24:21
我认为你应该这样使用,在Windows PS中:
venv-slither/Scripts/activate.ps1使用该命令为当前用户启用必要的执行策略后:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser为了安全起见,在您完成工作后,我将使用此命令返回到以前的策略:
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser还有其他方法可以临时设置执行。例如,我可以通过发出以下命令来设置当前PS的会话:
powershell.exe -ExecutionPolicy RemoteSigned* RemoteSigned或无限制,您可以参考此链接查看每种类型的策略允许或不允许使用哪些脚本的详细信息:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1
很抱歉发得太晚了,我刚刚发现了你的帖子,发现了同样的问题,测试了自己,它起作用了。
https://stackoverflow.com/questions/64694115
复制相似问题