我希望同时拥有Anaconda python v2和python v3环境。我在Microsoft的PowerShell中运行了两个Anaconda安装程序。然后创建python3 env我运行:
indexOf
但是,激活此env将忽略新的env:
db.products.aggregate([
{$match : {'Method':'PUT','Url':/.*widgets.*\/state$/ }},
{$group: {'_id':'$BrandId','total':{$sum: 1} }}
]);
..正如我们通过查看已安装的envs列表中的当前内容所看到的那样:
PS C:\Users\jo> conda create -n py3 python=3.4
Fetching package metadata: ....
Solving package specifications: .
Package plan for installation in environment C:\Anaconda\envs\py3:
The following NEW packages will be INSTALLED:
pip: 6.1.1-py34_0
python: 3.4.3-0
setuptools: 15.2-py34_0
Proceed ([y]/n)? y
Linking packages ...
[ COMPLETE ]|##################################################| 100%
#
# To activate this environment, use:
# > activate py3
#
当健全性统治时,PS C:\Users\jo> activate py3
Activating environment "py3"...
PS C:\Users\jo> python
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Dec 18 2014, 16:57:52) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>>
命令通过修改路径变量来执行此切换。在这种环境中我还需要做些什么才能让它发挥作用?
答案 0 :(得分:5)
先切换到cmd
,然后激活py3
:
> cmd
> activate py3
答案 1 :(得分:1)
如果从PowerShell(批处理文件)运行cmd.exe
shell脚本,PowerShell会生成cmd.exe
的实例来运行该脚本。如果批处理文件设置环境变量,则它们仅存在于生成的cmd.exe
实例中。一旦该实例终止(即,当脚本结束时),环境变量不会传播到调用进程(在本例中为PowerShell)。这是设计的。
如果要传播环境变量,可以在PowerShell中使用以下Invoke-CmdScript
函数:
function Invoke-CmdScript {
param(
[String] $scriptName
)
$cmdLine = """$scriptName"" $args & set"
& $Env:SystemRoot\system32\cmd.exe /c $cmdLine |
Select-String '^([^=]*)=(.*)$' | ForEach-Object {
$varName = $_.Matches[0].Groups[1].Value
$varValue = $_.Matches[0].Groups[2].Value
Set-Item Env:$varName $varValue
}
}
以下文章中有关此内容的更多信息:
Windows IT Pro: Take Charge of Environment Variables in PowerShell