virtualenv won't activate on windows

后端 未结 18 1625
走了就别回头了
走了就别回头了 2020-12-07 14:05

Essentially I cannot seem to activate my virtualenv environment which I create.

I\'m doing this inside of windows powershell through using

scripts\\a         


        
相关标签:
18条回答
  • 2020-12-07 14:40

    In powershell use

    Scripts\activate.ps1
    

    instead of activate.bat which doesn't work in powershell anymore.

    also deactivate by just typing

    deactivate
    

    at the command prompt

    0 讨论(0)
  • 2020-12-07 14:42

    If machine a 64 bit, open the x86 instance of PowerShell as Administrator & check (set) the execution policy. try this

    Set-ExecutionPolicy Unrestricted
    

    or

    Set-ExecutionPolicy Unrestricted -Force
    
    0 讨论(0)
  • 2020-12-07 14:42

    Based on the answers found here, I created a short tutorial for this with screenshots.

    • Python 3.7
    • Windows 10 64bits
    • PowerShell

    Hope it can help: https://github.com/harrywang/self-contained-project/wiki/How-to-setup-Python-3-virtual-environment-on-Windows-10

    0 讨论(0)
  • 2020-12-07 14:42
    C:\path> Set-ExecutionPolicy - Scope CurrentUser
    

    cmdlet Set-ExecutionPolicy at command pipeline position 1 Supply values for the following parameters: ExecutionPolicy: Unrestricted

    C:\path> Scripts\activate.ps1
    

    (new env)

    C:\path> deactivate
    
    C:\path> 
    

    This Worked

    0 讨论(0)
  • 2020-12-07 14:43

    This worked for me:

    You can simply open a normal (you do not need elevated access) cmd or powershell session (I use the embedded PS terminal in vscode) and type the following from the folder where the script file is e.g.: .venv\Scripts\Activate.ps1:

    powershell.exe -executionpolicy unrestricted -command .\Activate.ps1 -Scope CurrentUser

    and then you can run the activate command after that.

    Note: This will only allow that specific Script to run, and only by your logged in user.

    0 讨论(0)
  • 2020-12-07 14:43

    Delete the directory for that venv you created. And create a new one using the command:

    python -m venv myvenv
    

    Then see if the activate command works.

    0 讨论(0)
提交回复
热议问题