I’ve made a virtual environment that looks like this:
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.
2
Answers
Have you tried only typing
Venv in windows is a little tricky sometimes.
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
orSet-ExecutionPolicy Unrestricted
.Accept the change by typing
Y
.