Python activate 錯誤 – PSSecurityException

最近開始使用poetry建立虛擬環境,當我執行activate時出現以下錯誤。

.\activate : File C:\Users\Lu\PycharmProjects\xxxxx\examples\xxxxx\venv\Scripts\activate.ps1 cannot be loaded 
because running scripts is disabled on this system. For more information, see about_Execution_Policies at 
http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\activate
+ ~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

看起來是權限的問題。

解決方法

Get-ExecutionPolicy   // 查看當前的權限
Set-ExecutionPolicy RemoteSigned  // 設定權限
Get-ExecutionPolicy // 執行結果為RemoteSigned