virtualenv in PowerShell?

后端 未结 13 2086
悲&欢浪女
悲&欢浪女 2020-12-12 20:32

Hi fellow pythonistas, there seems to be a problem when virtualenv is used in PowerShell.

When I try to activate my environment in PowerShell like..

> env

13条回答
  •  鱼传尺愫
    2020-12-12 21:08

    I wrote a little script to activate it.

    # Don't forget to change execution policies
    # Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
    # More info https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7
    
    if (Test-Path env:VIRTUAL_ENV) {
        deactivate  
    }
    
    $env = .\venv\Scripts\activate.ps1
    
    # use $env to set variables, for instance $env:FLASK_APP = "main.py"
    

    Remember to save file with PowerShell extension .ps1.

提交回复
热议问题