本文介绍了virtualenv v16.7.2 powershell activate script: "你必须'source'这个脚本:PS>..\ENV\Scripts\activate"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

python v.3.7.4 上最新版本的 virtualenv (16.7.2) 为activate.ps1"增加了 4 行.脚本,在 Windows10 powerhsell 上运行时会出现错误:您必须源"此脚本:PS>..\ENV\Scripts\activate我该如何解决?(请注意,我已经阅读并完成了其他论坛问题中提到的所有内容以及与 windows 和 powershell 相关的 virtualenv 手册.)

我采取的步骤/尝试的事情:**

我已将执行策略设置为 RemoteSigned(按照其他论坛的建议):

Get-ExecutionPolicy -List范围执行策略----- ---------------机器策略未定义用户策略未定义进程未定义当前用户未定义本地机器远程签名

当我想激活 virtualenv 时,我运行 .\ENV\Scripts\activate

问题出在哪里

问题出在创建新虚拟环境时由 virtualenv 自动生成的 activate.ps1 脚本的第 3 到 6 行:

if (@($null,Internal") -notcontains $myinvocation.commandorigin) {Write-Host -Foreground red "你必须'source'这个脚本:PS>.$($myinvocation.invocationname)"33号出口}

似乎 $myinvocation.commandorigin 设置为 Runspace 而不是 Internal

问题

我该如何解决这个问题?有任何想法吗?谢谢 :)))请注意,我不想手动调整每个自动生成的 activate.ps1 文件.

解决方案

让我们看看那个错误信息:

你必须'source'这个脚本:PS>..\ENV\Scripts\activate

嗯... - PS> 可能只是提示,这给我们留下了:

 ..\ENV\Scripts\activate#^# |#看看这个人

那个,路径前面的那个孤独的.,就是powershell中的点源操作符.

根据 文档,它:

在当前范围内运行脚本,以便将脚本创建的任何函数、别名和变量添加到当前范围.

我没有看过 virtualenv,但我认为它需要定义一些变量并确保这些变量在脚本运行后仍然存在,它需要运行在当前范围内.

所以这是您必须运行的文字命令来修复它:

..\ENV\Scripts\activate

The Problem

Newest version of virtualenv (16.7.2) on python v.3.7.4 has 4 additional lines for the "activate.ps1" script, which when run on Windows10 powerhsell gives the error: You must 'source' this script: PS> . .\ENV\Scripts\activateHow do I fix this? (please note that I have read and done all that was mentioned on the other forum questions as well as the manual for virtualenv related to windows and powershell.)

Steps I took / things tried:**

I have set the execution policy to RemoteSigned (as recommended in other forums):

Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    RemoteSigned

When I want to activate virtualenv, I run .\ENV\Scripts\activate

Where the problem is

The problem is with lines 3 to 6 of the activate.ps1 script that is auto generated by virtualenv when you make a new virtual environment:

if (@($null,"Internal") -notcontains $myinvocation.commandorigin) {
    Write-Host -Foreground red "You must 'source' this script: PS> . $($myinvocation.invocationname)"
    exit 33
}

It seems that $myinvocation.commandorigin is set to Runspace instead of Internal

Question

How do I fix this? Any ideas? Thanks :)))Note that I don't want to manually adjust every auto-gen activate.ps1 file.

解决方案

Let's have a look at that error message:

Hmmmm... - PS> is probably just the prompt, which leaves us with this:

  . .\ENV\Scripts\activate
# ^
# |
# Check out this guy

That, the lonely . in front of the path, that is the dot-source operator in powershell.

According to the documentation, it:

I haven't had a look at virtualenv, but I assume it'll want to define a number of variables and to ensure that these persist after the script has run, it needs to be run in the current scope.

So this is the literal command you have to run to fix it:

. .\ENV\Scripts\activate

这篇关于virtualenv v16.7.2 powershell activate script: "你必须'source'这个脚本:PS>..\ENV\Scripts\activate"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 14:25
查看更多