Failed to activate for python3 using Anaconda on Windows 8.1

I would like to have both Anaconda python v2 and python v3 environment. I ran both Anaconda installers while running in Microsoft powershell. Then, to create python3 env, I run:

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
#

      

However, including this env ignores the new env:

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
>>>

      

.. as we can see by looking at what is current in the list of installed envs:

PS C:\Users\jo> conda env list
# conda environments:
#
py3                      C:\Anaconda\envs\py3
root                  *  C:\Anaconda

      

When sapience reigns, the command activate

executes this switch by modifying the path variable. Is there something else I need to do in this environment to get it working?

+3


source to share


2 answers


First switch to cmd

, then activate py3

:



> cmd
> activate py3

      

+4


source


If you run a shell cmd.exe

script from PowerShell (batch file), PowerShell starts an instance cmd.exe

to run the script. If the batch file sets environment variables, they only exist in the child instance cmd.exe

. Once that instance finishes (i.e. when the script finishes), environment variables are not propagated to the calling process (in this case PowerShell). This is by design.

If you want to propagate environment variables, you can use the following function Invoke-CmdScript

in PowerShell:

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
  }
}

      



More information on this in the following article:

Windows IT Pro: Take a Charge of Environment Variables in PowerShell

+1


source







All Articles