Conda: Activate environment not working on windows

Created on 12 Aug 2015  Â·  49Comments  Â·  Source: conda/conda

This morning I installed Anaconda 2.3 with Python 3 on Windows 7 64-bit.
Then I created a Python 2.7 environment in the usual way.
Then I activated it "activate py27" and received a message that it was activated.
Then I ran "python -V" and it reports Python 3.4, not Python 2.7.

Other people have also had this problem, e.g. Shantnu's comment on this page: http://pythonforengineers.com/python-on-windows-causing-you-pain-try-anaconda/

tag-shell

Most helpful comment

I figured it out on Windows: I was using Powershell, which apparently isn't compatible. However, there's an improvement that can be made: on Powershell there's no indication that it won't work or hasn't worked, you get the right messages but it silently fails. Not sure what wasn't working on my Mac but that's ok as well now.

Jeremy

—
Sent from Mailbox

On Sat, Aug 29, 2015 at 8:53 PM, DancingQuanta [email protected]
wrote:

What is your output to the command 'echo %PATH%' without quotes before and after activate command?

Reply to this email directly or view it on GitHub:
https://github.com/conda/conda/issues/1519#issuecomment-136034579

All 49 comments

How did you create your Python 2.7 environment?

I've tried this two ways:
1) Using the Anaconda launcher - new environment
creates a minimal python environment with Python itself and not much else.
2) From the command line:
conda create -n py27 python=2.7 anaconda

In both cases, typing 'activate py27' returns the message 'Activating environment "py27"...' without errors, but then typing 'python -V' returns 'Python 3.4.3 :: Anaconda 2.3.0 (64-bit).

Is it relevant that I've also tried this on my Mac, yesterday with a new Anaconda installation, and a similar failure to be able to successfully activate a new environment? And in another variation of my testing, I started with Anaconda that had python 2.7 in the root environment, created a new python 3 environment and tried to activate that, and it didn't work either.

In no cases have any errors been raised.

fyi, windows 8, batch command line, it seems to be working for me.

What is your output to the command 'echo %PATH%' without quotes before and after activate command?
The activate command should add the environment to your PATH.

I figured it out on Windows: I was using Powershell, which apparently isn't compatible. However, there's an improvement that can be made: on Powershell there's no indication that it won't work or hasn't worked, you get the right messages but it silently fails. Not sure what wasn't working on my Mac but that's ok as well now.

Jeremy

—
Sent from Mailbox

On Sat, Aug 29, 2015 at 8:53 PM, DancingQuanta [email protected]
wrote:

What is your output to the command 'echo %PATH%' without quotes before and after activate command?

Reply to this email directly or view it on GitHub:
https://github.com/conda/conda/issues/1519#issuecomment-136034579

I believe that it is possible to change anaconda environment within the PowerShell, I mainly use cygwin so I am using similar technique to get it working.

Every shell have its own set of environmental variables such as PATH, when a shell is started it inherit the system and user environment variables from Windows.

The activate script on Windows only work on old command prompt because the script add the path of a new environment to the old command prompt's environmental variables.
If you tried to execute the activate command on the PowerShell, the script works but it DOES not affect the PowerShell's environmental variables.
So you can't use the new environment in PowerShell however, the solution is to write a PowerShell script that adds the anaconda environment to the PowerShell environmental variables instead.

Here how I 'activate' a new anaconda environment in PowerShell manually:

PS C:\> python -V
Python 3.4.1 :: Anaconda 2.3.0 (64-bit)
PS C:\> $env:Path = "D:\Anaconda3\envs\py27;D:\Anaconda3\envs\py27\Scripts;" + $env:Path
PS C:\> python -V
Python 2.7.10 :: Anaconda 2.2.0 (64-bit)
PS C:\>

What I did is to add the path of the new environment and its Scripts directory to the Path of the PowerShell.
I have not tested this properly but the version of python I am using changed so hopefully this works for you.

To change back to old environment you have to restart powershell to clear its environmental variables.

Hope this make sense for you!

interestingly, this works from cmd.exe, but not from "Anaconda Command Prompt"

I can confirm that Anaconda Prompt has problems. After a fresh install, (de)activating worked from "Anaconda2" root environment, but after changing or deactivating environment, (de)activating didn't work anymore. But cmd.exe works.

Same issue here. Not working in Ipython QT console, not working in powershell; cmd works.

Same issue here, working only in cmd, not working in Powershell or babun

I'm not using powershell. I guess I have another issue. My windows account contains a space. This didn't use to be a problem; until recently (two weeks ago it worked...) I could create and activate envs from the command line. Today I got:

<No environment named "flask" exists in C:\Users\xxxx, or is not a valid conda installation directory.>

conda info --envs still reveals my envs, I just cannot reach them anymore. I can still set my env in the Anaconda console...2 years ago there was an issue with this (windows accounts with a space), but that was reported to be settled.

I don't want to change my name and directory. Any ideas?

@BjoernBerlin what is your version of conda-env? The issue would be part of that package currently. Please let us know, and in the meantime, we'll double-check our code there.

See https://github.com/conda/conda-env/blob/develop/bin/activate.bat#L6

I think you may be better if that line reads:

    FOR /F %%i IN ("%~dp0..\envs") DO set "CONDA_ENVS_PATH=%%~fi"

instead of

    FOR /F %%i IN ("%~dp0..\envs") DO set CONDA_ENVS_PATH=%%~fi

Can you try this on your Scripts\activate.bat file and see if it fixes your issue?

msarahan, that was quick.
I changed activate.bat, but still can't activate the envs. I guess something is wrong with all the paths, because conda update anaconda or conda update --all won't go through, either:
Could not open ... for writing, no such file or directory

conda info yields:
Current conda install: platform : win-64 conda version : 3.18.7 conda-build version : 1.14.1 python version : 3.4.3.final.0 requests version : 2.8.1 root environment : C:\Users\Administrator Bjoern\Anaconda3 (writable) default environment : C:\Users\Administrator Bjoern\Anaconda3 envs directories : C:\Users\Administrator package cache : C:\Users\Administrator\.pkgs channel URLs : https://repo.continuum.io/pkgs/free/win-64/ https://repo.continuum.io/pkgs/free/noarch/ https://repo.continuum.io/pkgs/pro/win-64/ https://repo.continuum.io/pkgs/pro/noarch/ config file : None is foreign system : False

Just a side note: https://pypi.python.org/pypi/virtualenvwrapper-win has the same problem.

Yes, I'm also one of those seeking a solution to this problem for quite a while (Win7/64-bit). I can confirm that cmd works, but unfortunately pressing Ctrl+D does exit the Python shell, unlike the Python interpreter called from the Anaconda shell.

Is there a fix on the way for this?

This should actually be long-fixed. Sorry for not posting here.

conda update conda-env

Should get you a version that handles spaces much better.

Hm, I must be experiencing a separate issue. The "activate {envname}" command is not found, and I attempt to use "activate.bat {envname}" and it says Activating environment "..." but upon using "conda info --env" it appears to have been unsuccessful as the environment is still set to root.

You are probably trying to use powershell. Only cmd.exe is supported right now. We hope to change that soon.

Ah.. that was it. I was using Cygwin. Thank you.

msarahan,
I seem to have the latest version of conda-env.

>conda update conda-env
Fetching package metadata: ....
# All requested packages already installed.
# packages in environment at C:\Users\chandrav\AppData\Local\Continuum\Anaconda:
#
conda-env                 2.4.5                    py27_0

@navneethc Ctrl-d behavior changed from python 2 to python 3. That's an
upstream change that honestly annoys me also. However, it is not related
to this issue. Please open a new issue if you feel it necessary.

On Wed, Jan 27, 2016, 00:25 navneethc [email protected] wrote:

msarahan,
I seem to have the latest version conda-env.

conda update conda-env
Fetching package metadata: ....

All requested packages already installed.

packages in environment at C:\Users\chandrav\AppData\Local\Continuum\Anaconda:

#
conda-env 2.4.5 py27_0

—
Reply to this email directly or view it on GitHub
https://github.com/conda/conda/issues/1519#issuecomment-175426547.

msarahan, Thanks for the reply, but my issue is still that I'm not able to actually activate and use the other environment from the Anaconda prompt, despite using the latest version of conda-env. I should have made it clear that the CTRL+D issue was just an aside. :-)

C:\Users\chandrav\AppData\Local\Continuum\Anaconda>conda update conda-env
Fetching package metadata: ....
# All requested packages already installed.
# packages in environment at C:\Users\chandrav\AppData\Local\Continuum\Anaconda:
#
conda-env                 2.4.5                    py27_0

C:\Users\chandrav\AppData\Local\Continuum\Anaconda>conda info --envs
# conda environments:
#
py3env                   C:\Users\chandrav\AppData\Local\Continuum\Anaconda\envs\py3env
root                  *  C:\Users\chandrav\AppData\Local\Continuum\Anaconda


C:\Users\chandrav\AppData\Local\Continuum\Anaconda>activate py3env
Deactivating environment "C:\Users\chandrav\AppData\Local\Continuum\Anaconda"...
Activating environment "C:\Users\chandrav\AppData\Local\Continuum\Anaconda\envs\py3env"...

[py3env] C:\Users\chandrav\AppData\Local\Continuum\Anaconda>python
Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec  7 2015, 14:10:42) [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://anaconda.org
>>>

[py3env] C:\Users\chandrav\AppData\Local\Continuum\Anaconda>

So this is a confusion that I've bumped into. If you run activate.bat while in the root of your root environment, it doesn't drop you into a new folder. You're still in the root of your root environment. Guess what else is in that folder? Python.exe - whatever version your root installation is. Thus, it appears that you haven't activated the environment, but the real issue is that it's finding the local python.exe before it even goes looking for stuff on PATH.

CD into a different folder, and you should see the correct Python.

Yes, cd-ing into the env folder is what I do now, but that sort of defeats the purpose of the activate command. :-)

Some of the things that are part of 'activation' does happen: e.g., PATH is prefixed with the environment path, the prompt is prefixed with the env name etc. But yes, it still calls the local/root version (in my case, 2.7).

No, you don't need to cd into the env folder - you just need to NOT be in
the root install folder. You can be absolutely anywhere else, and it
should work.

On Wed, Jan 27, 2016 at 8:55 AM navneethc [email protected] wrote:

Yes, cd-ing into the env folder is what I do now, but that sort of defeats
the purpose of the activate command. :-)

Some of the things that are part of 'activation' does happen: e.g., PATH
is prefixed with the environment path, the prompt is prefixed with the env
name etc. But yes, it still calls the local/root version (in my case, 2.7).

—
Reply to this email directly or view it on GitHub
https://github.com/conda/conda/issues/1519#issuecomment-175666962.

Yes, that works.

I seem to be having the same issue. I am testing out miniconda and I do not want to mess with my current python path settings so I am working out of the base directory. When I try to switch environments I get the following error.

c:\Users\Username\Portable Apps\Miniconda2\Scripts>activate snowflakes
Apps\Portable was unexpected at this time.

Even moving out of the directory I get the same error.

c:\Windows>"c:\Users\Username\Portable Apps\Miniconda2\Scripts\activate.bat" snowflakes
Apps\Portable was unexpected at this time.

Everyhting is up to date:

c:\Users\Username\Portable Apps\Miniconda2\Scripts>conda --version
conda 3.19.1

c:\Users\Username\Portable Apps\Miniconda2\Scripts>conda update conda-env
Fetching package metadata: ....
# All requested packages already installed.
# packages in environment at c:\Users\Username\Portable Apps\Miniconda2:
#
conda-env                 2.4.5                    py27_0

@Ron024 this is a new one - somehow the script is reversing "Portable Apps". I have tested it fairly thoroughly with spaces in paths, and haven't seen something like this. One thing you can do to help us debug is to edit the activate.bat script at the top, and replace

@echo off

with

@echo on

That should show us exactly where in the script this problem is showing up.

Here is the @echo on
error.txt

@Ron024 there are a couple of things strange in there:

  1. I haven't seen this script before with shortened path styles (Minic~1). I think this should work, but I haven't explicitly tested it. What OS are you on?
  2. You have several entries in your PATH with quotes. That's very bad. That breaks any batch file's ability to interpret your PATH as a single string. These are unnecessary, and also just bad. Please edit your PATH variable to remove all quotes. Spaces are OK in PATH, but quotes are not. See http://superuser.com/a/452357/184799 Note that this differs from the command prompt itself, where you should quote paths with spaces.

I am on Win 7 x32. I did not know that quotes weren't necessary in the path. It makes sense for the batch file. I removed them and it worked correctly, paths show up as full length.

So the activate script is working now?

Yes, it is working as it should.

Thanks. Closing this issue. Anyone in the future, please open a new one.

Hi
I also have an error in Windows 10 64 bit :

C:\WINDOWS\system32>conda info --envs
# conda environments:
#
tensorflow-gpu           C:\Program Files\Anaconda3\envs\tensorflow-gpu
root                  *  C:\Program Files\Anaconda3
C:\WINDOWS\system32>activate tensorflow-gpu
C:\WINDOWS\system32>pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.0.0-cp35-cp35m-win_x86_64.whl
tensorflow_gpu-1.0.0-cp35-cp35m-win_x86_64.whl is not a supported wheel on this platform.

I couldn't switch to my environment tensorflow-gpu
How to fix my problem ?
Many thanks

Can't change environment using activate

conda --version
4.13.4
Win10 Pro x64

Any ideas?

@PhanDuc, please do not install Anaconda into a location containing spaces.
@masepi, you need to give detailed output for what happens (i.e. what is printed out) when you try to change environment using activate.

This issue is probably not related to you are running into though.

Problem with powershell!
With cmd all is fine.

OK, we do not support PowerShell at present.

Hi folks,

I just execute the same command of the "Anaconda prompt", copied from the shortcut, in the PowerShell and it worked for me:

image

Hope help you too!

The solution proposed by @borgeslt is a good workaround to use it from PowerShell. Nevertheless at least it can (should) be documented somewhere.

In windows 10, click on the start menu and navigate to Anaconda, Click on Anaconda Prompt.... All commands should work without issues.

(C:\ProgramDataAnaconda3) C:\Users\pt>conda info --envs

conda environments:

#
27 C:\Users\pt\AppData\Local\conda\conda\envs\27
py27 C:\Users\pt\AppData\Local\conda\conda\envs\py27
spyder C:\Users\pt\AppData\Local\conda\conda\envs\spyder
twoseven C:\Users\pt\AppData\Local\conda\conda\envs\twoseven
root * C:\ProgramDataAnaconda3

(C:\ProgramDataAnaconda3) C:\Users\pt>activate py27

(py27) C:\Users\tarwireyip>conda info --envs

conda environments:

#
27 C:\Users\pt\AppData\Local\conda\conda\envs\27
py27 * C:\Users\pt\AppData\Local\conda\conda\envs\py27
spyder C:\Users\pt\AppData\Local\conda\conda\envs\spyder
twoseven C:\Users\pt\AppData\Local\conda\conda\envs\twoseven
root C:\ProgramDataAnaconda3

If you want a workaround for doing it from PowerShell the Quick-n-Dirty way, instead of rewriting the cmd batch file as a PowerShell ps1 script (which would be the _right_ solution), you can just run the current cmd script, and capture the environment changes and set them in PowerShell.

Here's an example of PowerShell script which will run _a cmd batch file with the same name from the same folder_, and import any changes it makes to the environment:

Push-Location $PSScriptRoot
$TempEnv = [IO.Path]::GetTempFileName()
# use the path without the extension to allow .bat or .cmd
$command = [IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand)
$param = $args -join " "

cmd.exe /c "$command $param && set > $TempEnv"
foreach($line in Get-Content $TempEnv){
    $name,$value = $line -split "=",2
    Set-Content Env:$name $value
}
Pop-Location

I know this is an old thread, but I have more experience with Anaconda3 on Ubuntu, this is my first try on Windows 10. Can't seem to be able to get to the Anaconda Prompt screen ,I end up with the following:
The system cannot find the path specified. Seems I am not the only one with this issue. I can't even check
"conda info --envs". I would hope that there is a fix for this.

Any assistance would be appreciated

Clive

@clived2 I am having the same problem. I install it and everything is ok. When I want to open the Anaconda prompt, it say The system cannot find the path specified.
I was looking at the bat files and I realized that these files are edited as below:
@echo off
call "C:Anaconda2\Scripts\conda" %*

Why do bat files are reedited by the computer? @msarahan

For windows, you can try "conda activate ". Worked for conda 5.2

If you want a workaround for doing it from PowerShell the Quick-n-Dirty way, instead of rewriting the cmd batch file as a PowerShell ps1 script (which would be the right solution), you can just run the current cmd script, and capture the environment changes and set them in PowerShell.
adobe premiere rush crack at forcrack
visit crackred for microsoft office 2016 product key
adobe indesign crack at keyslog

Was this page helpful?
0 / 5 - 0 ratings