I’m using VS Code and I have followed the steps in the docs to set it up for Python development: https://code.visualstudio.com/docs/python/python-tutorial.
But when trying to run a program I get the error:
can´t load the file C:VVSCodePython.venvScriptsActivate.ps1 because script execution is disabled on this system. For more information, see the about_Execution_Policies.
Even though I get the error, the program runs fine.
Python version: 3.12.1
VSCode version: 1.85.1
2
Answers
Run the command
get-executionpolicy
to verify your execution policy setting. If you getRestricted
, it means No scripts can be run and you can only use Windows PowerShell in interactive mode. If you getAllSigned
, it means you can run only scripts that have been digitally signed by a trusted publisher. If you getRemoteSigned
, it means you can run scripts that was created locally, but scripts that is downloaded must be digitally signed by a trusted publisher. If you getUnrestricted
, then there are no restrictions at all. This allows you to run unsigned scripts from any source but will warn when a script has been downloaded from the Internet.To remove the restrictions, you can either run
set-executionpolicy remotesigned
(preferable) orset-executionpolicy unrestricted
(if you’re running as admin). After this, you can activate your virtual environment usingvenvScriptsactivate
.To get more information on Set-ExecutionPolicy, run
get-help set-executionpolicy
. See Setting the PowerShell Execution Policy for more.You’re seeing this error because VSCode tries to activate your virtual environment by running the
Activate.ps1
script. However this is blocked by the execution policy.You can open PowerShell as an administrator and run the following command to change it:
You can also try to set cmd as the default terminal instead of PowerShell.