ffa*_*our 6 python powershell virtualenv windows-10
python v.3.7.4上的最新版本virtualenv(16.7.2)为“ activate.ps1”脚本增加了4行,当在Windows10上运行时,powerhsell会给出错误:You must 'source' this script: PS> . .\ENV\Scripts\activate
如何解决此问题?(请注意,我已经阅读并完成了其他论坛问题以及与Windows和Powershell相关的virtualenv手册中提到的所有内容。)
我已将执行策略设置为RemoteSigned(如其他论坛所建议):
Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
Run Code Online (Sandbox Code Playgroud)
当我想激活virtualenv时,我运行 .\ENV\Scripts\activate
问题出在创建新的虚拟环境时由virtualenv自动生成的activate.ps1脚本的第3至6行:
if (@($null,"Internal") -notcontains $myinvocation.commandorigin) {
Write-Host -Foreground red "You must 'source' this script: PS> . $($myinvocation.invocationname)"
exit 33
}
Run Code Online (Sandbox Code Playgroud)
似乎$myinvocation.commandorigin设置为Runspace而不是Internal
我该如何解决?有任何想法吗?谢谢:)))请注意,我不想手动调整每个自动生成的activate.ps1文件。
让我们看看该错误消息:
You must 'source' this script: PS> . .\ENV\Scripts\activate
嗯...- PS>可能只是提示,这让我们有了:
. .\ENV\Scripts\activate
# ^
# |
# Check out this guy
Run Code Online (Sandbox Code Playgroud)
那就是.路径前面的寂寞,那就是powershell中的点源运算符。
根据文档,它:
在当前范围内运行脚本,以便将脚本创建的所有函数,别名和变量添加到当前范围。
我没有看过virtualenv,但是我假设它将要定义许多变量,并确保在脚本运行后这些变量仍然存在,因此需要在当前作用域中运行。
因此,这是您必须运行以对其进行修复的文字命令:
. .\ENV\Scripts\activate
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2286 次 |
| 最近记录: |