簡體   English   中英

盡管更新了 ExecutionPolicy,但無法在 VSCode 中激活虛擬環境

[英]Cannot activate virtual environment in VSCode, despite updated ExecutionPolicy

我正在嘗試在 VSCode 中設置虛擬環境。

為此,我在 GitBash 中使用-m venv newproject創建了一個文件夾“newproject”。

問題是我無法激活虛擬環境,因為在此系統上禁用了運行腳本(以下代碼來自 VSCode 終端):

./activate : File C:\Users\name\OneDrive\Dokumente\py_scripts\newproject\Scripts\Activate.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:1
+ ./activate
./activate : File C:\Users\name\OneDrive\Dokumente\py_scripts\newproject\Scripts\Activate.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:1
+ ./activate
+ ~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

我覺得這很令人困惑,因為我嘗試將執行策略設置為管理員,通過 Powershell 將 RemoteSigned 和 Unrestricted 設置為 RemoteSigned 和 Unrestricted,但我仍然收到錯誤(以下代碼來自 PowerShell):

PS C:\windows\system32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
PS C:\windows\system32> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process    RemoteSigned
  CurrentUser       Undefined
 LocalMachine       Undefined


PS C:\windows\system32> Set-ExecutionPolicy Unrestricted -Scope Process

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
PS C:\windows\system32> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process    Unrestricted
  CurrentUser       Undefined
 LocalMachine       Undefined

盡管允許運行本地編寫的腳本,為什么我仍然收到錯誤消息?

謝謝!

我剛剛想通了。 必須在 VSCode 中允許腳本,而不是在單獨的 PowerShell window 中:

PS C:\Users\name\OneDrive\Dokumente\py_scripts\newproject\Scripts> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
PS C:\Users\name\OneDrive\Dokumente\py_scripts\newproject\Scripts> ./activate
(newproject) PS C:\Users\mikes\OneDrive\Dokumente\py_scripts\newproject\Scripts> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM