skip to Main Content

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

This is the environment I have created

2

Answers


  1. Run the command get-executionpolicy to verify your execution policy setting. If you get Restricted, it means No scripts can be run and you can only use Windows PowerShell in interactive mode. If you get AllSigned, it means you can run only scripts that have been digitally signed by a trusted publisher. If you get RemoteSigned, 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 get Unrestricted, 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) or set-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.

    Login or Signup to reply.
  2. can´t load the file C:VVSCodePython.venvScriptsActivate.ps1
    because script execution is disabled on this system.

    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:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    

    You can also try to set cmd as the default terminal instead of PowerShell.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search