問題描述
python v.3.7.4 上最新版本的 virtualenv (16.7.2) 為activate.ps1"增加了 4 行.腳本,在 Windows10 powerhsell 上運(yùn)行時會出現(xiàn)錯誤:You must 'source' this script: PS>..ENVScriptsactivate
我該如何解決?(請注意,我已經(jīng)閱讀并完成了其他論壇問題以及與 windows 和 powershell 相關(guān)的 virtualenv 手冊中提到的所有內(nèi)容.)
Newest version of virtualenv (16.7.2) on python v.3.7.4 has 4 additional lines for the "activate.ps1" script, which when run on Windows10 powerhsell gives the error: You must 'source' this script: PS> . .ENVScriptsactivate
How do I fix this? (please note that I have read and done all that was mentioned on the other forum questions as well as the manual for virtualenv related to windows and powershell.)
我已將執(zhí)行策略設(shè)置為 RemoteSigned(按照其他論壇的建議):
I have set the execution policy to RemoteSigned (as recommended in other forums):
Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
當(dāng)我想激活 virtualenv 時,我運(yùn)行 .ENVScriptsactivate
When I want to activate virtualenv, I run .ENVScriptsactivate
問題在于創(chuàng)建新虛擬環(huán)境時由 virtualenv 自動生成的 activate.ps1 腳本的第 3 到 6 行:
The problem is with lines 3 to 6 of the activate.ps1 script that is auto generated by virtualenv when you make a new virtual environment:
if (@($null,"Internal") -notcontains $myinvocation.commandorigin) {
Write-Host -Foreground red "You must 'source' this script: PS> . $($myinvocation.invocationname)"
exit 33
}
似乎 $myinvocation.commandorigin
設(shè)置為 Runspace 而不是 Internal
It seems that $myinvocation.commandorigin
is set to Runspace instead of Internal
我該如何解決這個問題?有任何想法嗎?謝謝 :)))請注意,我不想手動調(diào)整每個自動生成 activate.ps1
文件.
How do I fix this? Any ideas? Thanks :)))
Note that I don't want to manually adjust every auto-gen activate.ps1
file.
推薦答案
我們來看看那個錯誤信息:
Let's have a look at that error message:
您必須獲取"此腳本:PS>..ENVScriptsactivate
Hmmmm... - PS>
可能只是提示,給我們留下了這樣的提示:
Hmmmm... - PS>
is probably just the prompt, which leaves us with this:
. .ENVScriptsactivate
# ^
# |
# Check out this guy
那個,路徑前面那個孤獨(dú)的.
,也就是powershell中的dot-source operator.
That, the lonely .
in front of the path, that is the dot-source operator in powershell.
根據(jù) 文檔,它:
在當(dāng)前范圍內(nèi)運(yùn)行腳本,以便將腳本創(chuàng)建的任何函數(shù)、別名和變量添加到當(dāng)前范圍內(nèi).
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope.
我沒有看過 virtualenv
,但我認(rèn)為它需要定義一些變量并確保這些變量在腳本運(yùn)行后仍然存在,它需要運(yùn)行在當(dāng)前范圍內(nèi).
I haven't had a look at virtualenv
, but I assume it'll want to define a number of variables and to ensure that these persist after the script has run, it needs to be run in the current scope.
所以這是你必須運(yùn)行的 literal 命令來修復(fù)它:
So this is the literal command you have to run to fix it:
. .ENVScriptsactivate
這篇關(guān)于virtualenv v16.7.2 powershell activate 腳本:"你必須'source'這個腳本:PS>..ENVScriptsactivate"錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!