Cannot activate virtual environment in vscode

Question:

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:UsersuserDocumentsCodeflaskTutorial> envScriptsactivate

But when I run this line nothing happens?

PS C:UsersuserDocumentsCodeflaskTutorial> envScriptsactivate.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:UsersuserDocumentsCodeflaskTutorial>

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

Asked By: zampoan

||

Answers:

Have you tried only typing

envScriptsactivate

Venv in windows is a little tricky sometimes.

Answered By: Jose M. González

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.

Answered By: David
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.