嗨夥計pythonistas,在PowerShell中使用virtualenv時似乎有問題。?
當我嘗試激活我的環境中使用PowerShell如..
> ENV /腳本/激活
..沒有任何反應。 (shell提示符應該和PATH env變量一樣改變。)
我想問題是PowerShell會產生一個新的cmd。進程只是爲了運行activate.bat,因此在完成後渲染變化activate.bat對shell死了。
您對此問題有任何解決方法嗎? (我現在堅持使用cmd.exe)
嗨夥計pythonistas,在PowerShell中使用virtualenv時似乎有問題。?
當我嘗試激活我的環境中使用PowerShell如..
> ENV /腳本/激活
..沒有任何反應。 (shell提示符應該和PATH env變量一樣改變。)
我想問題是PowerShell會產生一個新的cmd。進程只是爲了運行activate.bat,因此在完成後渲染變化activate.bat對shell死了。
您對此問題有任何解決方法嗎? (我現在堅持使用cmd.exe)
Here是一個包含Powershell腳本的文章,它允許您運行持久修改其環境變量的批處理文件。該腳本將任何環境變量更改傳回給調用的PowerShell環境。
快速解決方法是調用cmd,然後從cmd會話中運行activate.bat。例如:
PS C:\my_cool_env\Scripts> cmd
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\my_cool_env\Scripts>activate.bat
(my_cool_env) C:\my_cool_env\Scripts>
這對我有效。非常容易。謝謝! – irene 2017-08-09 11:07:21
The latest version of virtualenv支持PowerShell中出的現成。
只要確保你運行:的
Scripts\activate.ps1
代替
Scripts\activate
後者將執行activate.bat
,這不會對PowerShell的工作。
您可能需要運行'set-executionpolicy RemoteSigned'來允許腳本運行(我之前設置爲'Restricted')[docs](http://technet.microsoft.com/en-us/library/ee176961.aspx ) – 2012-12-22 08:29:53
,只需鍵入'deactivate'來撤消 – 2017-05-04 13:35:19
有沒有辦法使用這種方法改變提示的顏色? – 2017-06-04 03:59:31
試試這個: . .\env\Scripts\activate.ps1
手錶點和空間
。\ [my-venv] \ Scripts \ activate.ps1爲我工作。 – 2016-03-31 18:28:49
這個錯誤發生因安全措施,不會讓腳本,您無需批准的在系統上執行。您可以通過打開具有管理員權限的PowerShell中這樣做(搜索PowerShell的主菜單,並選擇從上下文菜單管理員身份運行),並進入:
設置executionpolicy下RemoteSigned
更多: http://www.faqforge.com/windows/windows-powershell-running-scripts-is-disabled-on-this-system/
我寫了這個快速的小腳本來處理我的激活和啓動的開發服務器。
$ep = Get-ExecutionPolicy
if ($ep -eq 'RemoteSigned') {
$root = "C:\Users\ALeven\OneDrive\!code_projects\!django_projects\"
$test = Read-Host -Prompt 'Would you like to activate the python environment? y/n'
if ($test -eq 'y') {
$activatestr = ($root + "\work_venv\Scripts\Activate.ps1")
& $activatestr
}
$test = Read-Host -Prompt 'Would you like to run the python server? y/n'
if ($test -eq 'y') {
$whichserver = Read-Host -Prompt 'Enter the name of the project.'
$path = ($root + $whichserver)
$runserverstr = ($path + "\manage.py")
python.exe $runserverstr runserver
}
} else {
Write-host "Execution Policy does not allow this script to run properly"
Write-host "If you have the proper permissions,"
Write-Host "Please close powershell,"
Write-host "then right click the powershell icon and run as administrator"
Write-host "Once in the powershell environment, execute the following:"
Write-host "Set-ExecutionPolicy RemoteSigned -Force"
}
享受。
謝謝Vinay,清楚地解釋了這個問題。 – 2009-09-02 02:38:29
這有效,但不能添加提示參數。在設置提示符之前,必須有一個可以調用Write-Host的activate.ps1。 – 2011-04-05 14:59:55
這個答案不再有效,因爲virtualenv支持powershell開箱即用,正如http://stackoverflow.com/questions/1365081/virtualenv-in-powershell/10030999#10030999 – 2014-03-14 21:45:15