2013-09-28 44 views
3

在PyCharm設置我的終端是Windows PowerShell中,但是當我嘗試在終端使用的virtualenv:如何運行終端作爲管理員使用的virtualenv

Import-Module virtualenvwrapper 

(我在啓動這個命令劇本,但只是單獨包括爲簡便起見,命令)

我得到以下錯誤:

Import-Module : File C:\Users\Sean\Documents\WindowsPowerShell\Modules\virtualenvwrapper\support.psm1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details. 
At line:1 char:14 
+ Import-Module <<<< virtualenvwrapper 
    + CategoryInfo   : NotSpecified: (:) [Import-Module], PSSecurityException 
    + FullyQualifiedErrorId : RuntimeException,Microsoft.PowerShell.Commands.ImportModuleCommand 

所以我嘗試啓用腳本執行(像我一樣對PowerShell的外面PyCharm的):

Set-ExecutionPolicy RemoteSigned 

但得到以下錯誤(我運行的PowerShell作爲管理員)避免PyCharm之外這個錯誤:

Set-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. 
At line:1 char:20 
+ Set-ExecutionPolicy <<<< RemoteSigned 
    + CategoryInfo   : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAccessException 
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand 

所以我能做些什麼才能夠從PyCharm終端使用virtualenv?

  • Windows 7的
  • 的Python 2.7
  • PyCharm社區版3.0
+1

您是否曾嘗試以管理員身份運行PyCharm? – Antony

回答

6

的權限錯誤你正在通過PowerShell的不具有機器的管理員權限造成的。快速解決方案是使用Run as Administrator啓動Powershell。從那裏,你可以使用Set-ExecutionPolicy

Set-ExecutionPolicy RemoteSigned 

此外,您可能需要調用Set-ExecutionPolicy時使用的-Scope參數。有時在子進程中運行Powershell時,所使用的執行策略與獨立運行PowerShell時不同。

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser 
+1

謝謝!設置-Scope參數有訣竅。 – Robinson

0

的另一種方式。如果你可以選擇使用UAC - User Access Control,你可以降低到允許的程序執行。在一個域中,這可以根據GPO/LGPO設置。試圖超越這些設置時要小心。

相關問題