0

I am getting start with VS Code to learn python on a second hand laptop. Every time I open the VS Code, I always encounter this error message in the terminal. I did not do any adjustment to PowerShell as I am a complete beginner.

. : File C:\Users\user\Documents\WindowsPowerShell\profile.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.
At line:1 char:3
+ . 'C:\Users\user\Documents\WindowsPowerShell\profile.ps1'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException     
    + FullyQualifiedErrorId : UnauthorizedAccess

Even though the error message displays in the terminal, there currently no issue executing python codes as of now. The error code also exist in the "Select Windows PowerShell" .

enter image description here

As of this writing, I suspect that the error message is a result during the installation of VS Code. Nevertheless, I am unsure if the previous owner did any adjustment in the PowerShell or not.


Ending Notes / Update

Does anyone encounter the same PowerShell error when initializing the VS Code? What are your recommended solutions?

Thank you in advance for your responses. I will keep you posted If I find a solution for this.

Lee.J
  • 23
  • 5
  • This is not related to Python or VS Code. The error message clearly says "running scripts is disabled on this system" and the link provided will tell you what the reason is and how to solve it. Basically you have to allow Powershell scripts to run with ```Set-ExecutionPolicy``` cmdlet. – Omid Shojaee Feb 21 '23 at 13:20
  • Thank you for the reply. I will change the tags for this question. I have reviewed the documentations for this and run `Get-ExecutionPolicy` and the system is showing that the current policy is “Restricted”. Upon reviewing, I have a question regarding a suitable ExecutionPolicy for programming. Would an AllSigned policy is suitable for a local script for VS Code? `Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope UserPolicy` – Lee.J Feb 21 '23 at 13:38
  • The `RemoteSigned` PowerShell [execution policy](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Execution_Policies) is a commonly used compromise between convenience and security: it allows execution of scripts originating from the local file-system or from network shares, but blocks those that were downloaded from the internet via a web browser, email client or messenger application, unless they are [signed](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Signing). – mklement0 Feb 21 '23 at 15:26

1 Answers1

0

The Set-ExecutionPolicy is limited to Powershell only -if you don't already know. Allsigned for user scope is a good practice if every script you're using is signed.

If your purpose is to use PS prompt for Python, it should be fine. If you need to write PS code/script, you'll need to sign them!

About Execution Policy

Does it answer your question?

  • Thank you for the clarifications! As of now, I am only executing Python codes through VS Code TERMINAL. But during the initializing of the Shell this PS “Restricted” error always show on in TERMINAL. As my current working scope is not involving PS, I think I will leave it as the default setting **(Restricted)**. Nevertheless thank you again for your help!! – Lee.J Feb 22 '23 at 09:22