简体   繁体   English

virtualenv v16.7.2 powershell 激活脚本:“您必须‘源’此脚本:PS> . .\\ENV\\Scripts\\activate”错误

[英]virtualenv v16.7.2 powershell activate script: "You must 'source' this script: PS> . .\ENV\Scripts\activate" error

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\\activate python v.3.7.4 上最新版本的 virtualenv (16.7.2) 为“activate.ps1”脚本增加了 4 行,在 Windows10 powerhsell 上运行时会出现错误: You must 'source' this script: PS> . .\\ENV\\Scripts\\activate You must 'source' this script: PS> . .\\ENV\\Scripts\\activate How do I fix this? You must 'source' this script: PS> . .\\ENV\\Scripts\\activate我该如何解决这个问题? (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.) (请注意,我已经阅读并完成了其他论坛问题以及与 windows 和 powershell 相关的 virtualenv 手册中提到的所有内容。)

Steps I took / things tried:**我采取的步骤/尝试的事情:**

I have set the execution policy to RemoteSigned (as recommended in other forums):我已将执行策略设置为 RemoteSigned(按照其他论坛的建议):

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当我想激活 virtualenv 时,我运行.\\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:问题出在创建新虚拟环境时 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
}

It seems that $myinvocation.commandorigin is set to Runspace instead of Internal似乎$myinvocation.commandorigin设置为Runspace而不是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.谢谢 :))) 请注意,我不想手动调整每个 auto-gen activate.ps1文件。

Let's have a look at that error message:让我们来看看那个错误信息:

You must 'source' this script: PS> . .\\ENV\\Scripts\\activate

Hmmmm... - PS> is probably just the prompt, which leaves us with this:嗯... - PS>可能只是提示,这给我们留下了这个:

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

That, the lonely .那个,寂寞. in front of the path, that is the dot-source operator in powershell.路径前面,就是powershell中的点源操作符

According to the documentation , it:根据文档,它:

Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope.在当前作用域中运行脚本,以便将脚本创建的任何函数、别名和变量添加到当前作用域。

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.我没有看过virtualenv ,但我假设它需要定义许多变量并确保这些变量在脚本运行后持续存在,它需要在当前范围内运行。

So this is the literal command you have to run to fix it:所以这是你必须运行的文字命令来修复它:

. .\ENV\Scripts\activate

I have also faced this issue.我也遇到过这个问题。 To solve this I created a new virtualenvironment as follows:为了解决这个问题,我创建了一个新的虚拟环境,如下所示:

python -m venv directory-name

To activate:激活:

Scripts>./activate

And Now it's working fine...现在它工作正常......

Screenshot attached for reference.附上截图供参考。 I've just encountered the same issue but I did the following:我刚刚遇到了同样的问题,但我做了以下事情:

  1. Create a new virtual environment;创建一个新的虚拟环境;

    python -m venv directory

  2. Navigate into the newly created directory;导航到新创建的目录;

    cd directory

  3. Activate the virtual environment.激活虚拟环境。

    .\\Scripts\\activate

This resolved my problem.这解决了我的问题。 I hope it helps...我希望它有帮助...

I Also Faced the same issue solved it by using this :我也面临同样的问题,通过使用这个解决了它:

Created A Virtual Environment By : virtualenv environment创建虚拟环境作者:virtualenv environment

After Creating Virtual Environment创建虚拟环境后

I activated it by using :我通过使用激活它:

source environment/bin/activate 

And It activated my Virtual Environment它激活了我的虚拟环境

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM