1

I've made a virtual environment that looks like this: enter image description here

When I run the following line it gives me an error:

PS C:\Users\user\Documents\Code\flaskTutorial> env\Scripts\activate

But when I run this line nothing happens?

PS C:\Users\user\Documents\Code\flaskTutorial> env\Scripts\activate.bat

I've read that windows doesnt run .bat files, but how do I activate my environment in vscode terminal so that it says something like this?

(env) PS C:\Users\user\Documents\Code\flaskTutorial>

Note: typing env\Scripts\activate in cmd does activate it in cmd, but I would like to work in vscode.

zampoan
  • 57
  • 7
  • What kind of error do you get when you run ``.\env\Scripts\activate`` in VS Code terminal? – David May 26 '23 at 10:17
  • 1
    .\env\Scripts\activate : File C:\Users\Zheng Yao\Documents\Code\flaskTutorial\env\Scripts\activate.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. – zampoan May 26 '23 at 10:22
  • You can change the execution policies of PowerShell, I have written an answer on how to do so. Please accept it if solved your problem. – David May 26 '23 at 10:44

2 Answers2

1

The error message indicates that the execution of PowerShell scripts is disabled on your system, which is preventing the activation script from running in Visual Studio Code.

You have to options: either change the Powershell Execution Policy or change the default terminal of VS Code to CMD.

For the Default terminal option see VSCode Change Default Terminal

  • Open a PowerShell terminal with administrative privileges. To do this, right-click on the PowerShell icon and select "Run as administrator".

  • Run: Get-ExecutionPolicy

  • If the execution policy is set to "Restricted" or "AllSigned", it means that PowerShell is preventing the execution of scripts. To enable script execution, you can set the execution policy to "RemoteSigned" or "Unrestricted" (more permission, but higher risk). Run one of the following commands to set the execution policy:

Run either Set-ExecutionPolicy RemoteSigned or Set-ExecutionPolicy Unrestricted.

Accept the change by typing Y.

David
  • 173
  • 12
0

Have you tried only typing

env\Scripts\activate

Venv in windows is a little tricky sometimes.

  • yep, it says an error: env\Scripts\activate : File C:\Users\Zheng Yao\Documents\Code\flaskTutorial\env\Scripts\activate.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. – zampoan May 26 '23 at 10:11