conda/conda-build

Windows error: "conda activate" fails because shell is not initialized

nicoddemus opened this issue Β· 28 comments

Hi,

After updating to conda 4.6.1, I'm getting this error when I try to build a recipe:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

I still get this error even after executing conda init cmd.exe and restarting the shell. I've also executed conda init cmd.exe with base environment active, but obtain the same results.

Using the same conda and conda-build combinations work on Linux.

Relevant conda info:

     active environment : base
    active env location : W:\Miniconda3
            shell level : 1
       user config file : C:\Users\bruno\.condarc
 populated config files : W:\Miniconda3\.condarc
          conda version : 4.6.1
    conda-build version : 3.16.3
         python version : 3.7.1.final.0
       base environment : W:\Miniconda3  (writable)
           channel URLs : https://<mirrorurl>/conda-channel/esss/win-64
                          https://<mirrorurl>/conda-channel/esss/noarch
                          https://<mirrorurl>/conda-channel/mirror-main/win-64
                          https://<mirrorurl>/conda-channel/mirror-main/noarch
                          https://<mirrorurl>/conda-channel/mirror-conda-forge/win-64
                          https://<mirrorurl>/conda-channel/mirror-conda-forge/noarch
          package cache : W:\Miniconda3\pkgs
                          C:\Users\bruno\.conda\pkgs
                          C:\Users\bruno\AppData\Local\conda\conda\pkgs
       envs directories : W:\Miniconda3\envs
                          C:\Users\bruno\.conda\envs
                          C:\Users\bruno\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.6.1 requests/2.21.0 CPython/3.7.1 Windows/10 Windows/10.0.17134
          administrator : True
             netrc file : None
           offline mode : False

Any advice appreciated. πŸ‘

cc @prusse-martin

@nicoddemus please update conda-build. 3.17.7+ should be good here.

Hi @msarahan,

Thanks for the lightning fast response.

I should have mentioned this, but I have tried to update the conda-build version to the latest one, but it fails with this message:

Ξ» conda install conda-build=3.17.7
Collecting package metadata: done
Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - conda-build=3.17.7
  - conda[version='>=4.6.1']
Use "conda search <package> --info" to see the dependencies for each package.

Which is strange because I'm using conda 4.6.1:

Ξ» conda --version
conda 4.6.1

bizarre. That's a new one to me. It looks like you have your own mirrors rather than using our servers. Are those mirrors up-to-date?

Hmm they should be, they update every 2 hours:

Ξ» conda search conda-build
...
conda-build                   3.17.7          py27_0  conda-channel/mirror-conda-forge
conda-build                   3.17.7          py36_0  conda-channel/mirror-conda-forge
conda-build                   3.17.7          py37_0  conda-channel/mirror-conda-forge
conda-build                   3.17.8          py27_0  conda-channel/mirror-conda-forge
conda-build                   3.17.8          py36_0  conda-channel/mirror-conda-forge
conda-build                   3.17.8          py37_0  conda-channel/mirror-conda-forge

Strangely enough, using the default channels to update conda and conda-build works:

Ξ» conda install conda-build=3.17.7 -c defaults
Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: W:\Miniconda3

  added / updated specs:
    - conda-build=3.17.7


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-build-3.17.7         |           py37_0         536 KB  defaults
    libarchive-3.3.3           |       h0643e63_2         1.4 MB  defaults
    lz4-c-1.8.1.2              |       h2fa13f4_0         217 KB  defaults
    lzo-2.10                   |       h6df0209_2         154 KB  defaults
    ------------------------------------------------------------
                                           Total:         2.3 MB

Even more strange, if I use conda-forge directly it also works:

conda install conda-build=3.17.7 -c conda-forge

So the "update issue" is somehow related to our mirrors.

Further investigation suggests that it is because of the order of our mirrors: the first channel is an internal channel with a custom python build (with MSVC2010), which is taking precedence and generating the conflicts:

Ξ» conda install conda=4.6.1 conda-build=3.17.8 python=3.7.1
Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - conda-build=3.17.8 -> enum34 -> python=2.7
  - python=3.7.1
Use "conda info <package>" to see the dependencies for each package.

Strangely I would expect the above command to work, because I believe conda should be honoring the python=3.7.1 package?


After managing to update to the latest conda build, indeed this solved my problem. πŸ˜…

Thanks @msarahan for nudging me into the right direction! πŸ‘

Writing my findings here in case it helps someone in the future.

We have two mirrors, one mirroring conda-forge (in full) and another mirroring main (with a whitelist of selected packages). Our intent is to get most of the packages from conda-forge and a few others from anaconda (specially the ones compiled with mkl support for speed).

So our channel list is:

  • esss (internal packages)
  • main (whitelist of selected packages)
  • conda-forge (practically everything)

When trying to install the latest conda-build, I was getting this error:

Ξ» conda install conda=4.6.1 conda-build=3.17.8 python=3.7.1
Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - conda-build=3.17.8 -> enum34 -> python=2.7
  - python=3.7.1
Use "conda info <package>" to see the dependencies for each package.

It isn't clear which package is actually missing that would solve the requirements, so I tried a lot of things (conda info between conda-build 3.16 and 3.18 for example).

In the end the method which clearly stated which packages were missing was to add the defaults channel to the end of the channel list. Then executing the conda install command above with --dry-run, conda would show for each package from which channel it was coming from, making it clear to see which packages were missing.

In my case, it was liblief, pylibef, and libarchive. While the first two were relatively easy to notice because they were missing on conda-forge, conda-build needed a very specific build of libarchive which was not available on conda-forge.

Linux error: "conda activate" fails because shell is not initialized

Hi,
After updating to conda 4.6.11, I'm getting this error when I try to build a recipe:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

$ conda init <SHELL_NAME>

Currently supported shells are:

  • bash
  • fish
  • tcsh
  • xonsh
  • zsh
  • powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

Here is my Relevant conda info:

 active environment : None
   user config file : /home/jocelina/.condarc

populated config files : /home/jocelina/.condarc
conda version : 4.6.11
conda-build version : 3.10.5
python version : 3.6.8.final.0
base environment : /home/jocelina/anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/linux-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /home/jocelina/anaconda3/pkgs
/home/jocelina/.conda/pkgs
envs directories : /home/jocelina/anaconda3/envs
/home/jocelina/.conda/envs
platform : linux-64
user-agent : conda/4.6.11 requests/2.21.0 CPython/3.6.8 Linux/4.18.0-17-generic ubuntu/18.04.2 glibc/2.27
UID:GID : 1000:1000
netrc file : None
offline mode : False

hi @nicoddemus,

I am currently getting the exact same error message when using the command conda activate to activate an environment, though since I am new to coding I'm hoping the solution is more simple than yours was. I had just installed Git Bash and Anaconda earlier that day, and hadn't changed anything before building this new environment from the .yml file within (https://github.com/earthlab/earth-analytics-python-env).

$ conda info

 active environment : None
   user config file : Z:\.condarc

populated config files :
conda version : 4.6.14
conda-build version : 3.17.8
python version : 3.7.3.final.0
base environment : C:\Users\kdw9736\AppData\Local\Continuum\anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/win-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\kdw9736\AppData\Local\Continuum\anaconda3\pkgs
Z:.conda\pkgs
C:\Users\kdw9736\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\kdw9736\AppData\Local\Continuum\anaconda3\envs
Z:.conda\envs
C:\Users\kdw9736\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/4.6.14 requests/2.21.0 CPython/3.7.3 Windows/10 Windows/10.0.17763
administrator : False
netrc file : None
offline mode : False

Here are my environments:

$ conda env list

conda environments:

base * C:\Users\kdw9736\AppData\Local\Continuum\anaconda3
earth-analytics-python C:\Users\kdw9736\AppData\Local\Continuum\anaconda3\envs\earth-analytics-python

I tried updating conda-forge and it didn't throw an error:

$ conda install conda-build=3.17.8 -c conda-forge
Collecting package metadata: done
Solving environment: done

Package Plan

environment location: C:\Users\kdw9736\AppData\Local\Continuum\anaconda3

added / updated specs:
- conda-build=3.17.8

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
conda-4.6.14               |           py37_0         2.1 MB  conda-forge
conda-build-3.17.8         |           py37_1         524 KB  conda-forge
------------------------------------------------------------
                                       Total:         2.6 MB

The following packages will be UPDATED:

conda-build pkgs/main::conda-build-3.17.8-py37_0 --> conda-forge::conda-build-3.17.8-py37_1

The following packages will be SUPERSEDED by a higher-priority channel:

certifi pkgs/main --> conda-forge
conda pkgs/main --> conda-forge

Proceed ([y]/n)? y

Downloading and Extracting Packages
conda-build-3.17.8 | 524 KB | ################################################################################################################### | 100%
conda-4.6.14 | 2.1 MB | ################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

I figure this is a stab in the dark given my minimal experience, but appreciate any advice!

On the windows environment use "anaconda prompt" instead of "command prompt".

Go to search.
Type "anaconda prompt" and open it.
Then type "conda activate <env_name>

most cleaner option will be

eval "$(conda shell.bash hook)"
conda activate my_env

To retain a familiar bash terminal feel. I downloaded Git bash, and created a .bashrc file in /c/Users//.
And pasted this into the .bashrc. This will initialise your git bash terminal whenever you start it, it is essentially the same thing that is placed in Linux/macOS ~/.bashrc or ~/.bash_profile

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/c/Users/<user>/Anaconda3/bin/conda.exe' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/c/Users/<user>/Anaconda3/etc/profile.d/conda.sh" ]; then
        . "/c/Users/<user>/Anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/c/Users/<user>/Anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

It happened to me too, but in my case I solved the problem in this way: I moved to the Anaconda directory with the cd command and wrote the comand conda activate nameoftheenviroment.

I've been attempting to deal with this issue all evening. I'm attempting to run code in the VSCode terminal and get the "Your shell has not been properly configured..." I'd like to try some of these solutions but I have no idea what "nameoftheenvironment", "my_env", "<your_environment>" mean. I'm assuming that these are placeholders but I don't know what to replace them with. Help please.

"nameoftheenvironment" is the name that you have asgin to your the environment.

Yeah, ummm...that didn't help.

On the windows environment use "anaconda prompt" instead of "command prompt".

Go to search.
Type "anaconda prompt" and open it.
Then type "conda activate <env_name>

Thanks!

yichangyu: Thank you. Very easy to follow advice. I appreciate it.

yichangyu: Thank you. Very easy to follow advice. I appreciate it.

Hi, IΒ΄ve your same problem : I donΒ΄t have idea which is my enviroment name ?

C:\Users\pc>conda --version
conda 4.8.4

C:\Users\pc>conda info

 active environment : base
active env location : C:\ProgramData\Anaconda3
        shell level : 1
   user config file : C:\Users\pc\.condarc

populated config files : C:\Users\pc.condarc
conda version : 4.8.4
conda-build version : 3.17.7
python version : 3.7.3.final.0
virtual packages :
base environment : C:\ProgramData\Anaconda3 (read only)
channel URLs : https://repo.anaconda.com/pkgs/main/win-32
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/win-32
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-32
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\ProgramData\Anaconda3\pkgs
C:\Users\pc.conda\pkgs
C:\Users\pc\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\pc.conda\envs
C:\ProgramData\Anaconda3\envs
C:\Users\pc\AppData\Local\conda\conda\envs
platform : win-32
user-agent : conda/4.8.4 requests/2.24.0 CPython/3.7.3 Windows/7 Wi
ndows/6.1.7601
administrator : False
netrc file : None
offline mode : False

C:\Users\pc>conda activate base

C:\Users\pc>eval "$(conda shell.bash hook)"
"eval" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

C:\Users\pc>conda activate my_env
Could not find conda environment: my_env
You can list all discoverable environments with conda info --envs.

C:\Users\pc>conda activate <env_name>
La sintaxis del comando no es correcta.

C:\Users\pc>conda activate <env_name>

conda env list lists all your existing conda environments.

For conda versions older than 4.4 the command is as follows for different types of operating systems::

source activate

For Linux and macOS OR

activate

For Windows. You will have to remove the conda keyword from the command.

(The above text was extracted from https://kodlogs.com/34141/command-not-found-error-your-shell-has-not-been-properly-configured-to-use-conda-activate)

I got the "conda activate" fails because shell is not initialized. I'm using Git Bash with conda version 4.9.2.
I solved it by:

  1. open shell (in my case Git Bash)
  2. type: source ~/miniconda3/etc/profile.d/conda.sh ((note: use anaconda3 if that's what you installed))
  3. type: conda init
  4. Restart your shell
  5. type: conda init bash ((note: I guess bash should be changed with the shell you use))
  6. Restart your shell

If you are using Git Bash on Windows and if it is giving 'You shell has not been configured properly' message, just run:

conda init bash

It worked for me. I did not want to try out anything harsh using the above suggestions because I did not want to mess up my environments.

hi @nicoddemus,

I am currently getting the exact same error message when using the command conda activate to activate an environment, though since I am new to coding I'm hoping the solution is more simple than yours was. I had just installed Git Bash and Anaconda earlier that day, and hadn't changed anything before building this new environment from the .yml file within (https://github.com/earthlab/earth-analytics-python-env).

$ conda info

 active environment : None
   user config file : Z:\.condarc

populated config files :
conda version : 4.6.14
conda-build version : 3.17.8
python version : 3.7.3.final.0
base environment : C:\Users\kdw9736\AppData\Local\Continuum\anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/win-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\kdw9736\AppData\Local\Continuum\anaconda3\pkgs
Z:.conda\pkgs
C:\Users\kdw9736\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\kdw9736\AppData\Local\Continuum\anaconda3\envs
Z:.conda\envs
C:\Users\kdw9736\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/4.6.14 requests/2.21.0 CPython/3.7.3 Windows/10 Windows/10.0.17763
administrator : False
netrc file : None
offline mode : False

Here are my environments:

$ conda env list

conda environments:

base * C:\Users\kdw9736\AppData\Local\Continuum\anaconda3
earth-analytics-python C:\Users\kdw9736\AppData\Local\Continuum\anaconda3\envs\earth-analytics-python

I tried updating conda-forge and it didn't throw an error:

$ conda install conda-build=3.17.8 -c conda-forge
Collecting package metadata: done
Solving environment: done

Package Plan

environment location: C:\Users\kdw9736\AppData\Local\Continuum\anaconda3

added / updated specs:

  • conda-build=3.17.8

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
conda-4.6.14               |           py37_0         2.1 MB  conda-forge
conda-build-3.17.8         |           py37_1         524 KB  conda-forge
------------------------------------------------------------
                                       Total:         2.6 MB

The following packages will be UPDATED:

conda-build pkgs/main::conda-build-3.17.8-py37_0 --> conda-forge::conda-build-3.17.8-py37_1

The following packages will be SUPERSEDED by a higher-priority channel:

certifi pkgs/main --> conda-forge
conda pkgs/main --> conda-forge

Proceed ([y]/n)? y

Downloading and Extracting Packages
conda-build-3.17.8 | 524 KB | ################################################################################################################### | 100%
conda-4.6.14 | 2.1 MB | ################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

I figure this is a stab in the dark given my minimal experience, but appreciate any advice!

Run conda init bash to setup conda properly in your GitBash

most cleaner option will be

eval "$(conda shell.bash hook)"
conda activate my_env

This works for me when trying to fix the same error in Emacs shell. I am wondering if there is a way to make this stick and be applied when the new shell is loaded?

most cleaner option will be
eval "$(conda shell.bash hook)"
conda activate my_env

This works for me when trying to fix the same error in Emacs shell. I am wondering if there is a way to make this stick and be applied when the new shell is loaded?

I was having the same problem and this worked for me too. I added eval "$(conda shell.bash hook)" to .bash_profile and it seems to be working to "make it stick."

Found an easy solution to get Conda to work inside VSCode on Windows.

Change this setting:
"terminal.integrated.defaultProfile.windows": "Command Prompt"

This will change the default terminal launched when clicking play button from powershell to cmd. Anaconda seems to not set itself up correctly in powershell, but runs fine in cmd prompt.

hi @iggirex can you please explain how to get this done

So I've had this issue with powershell and cmder for over a year now, it frustrated me a year ago and decided to never use cmder again ... until a couple days ago when I decided to try it again and I cannot for the life of me figure out what is wrong. Most likely from my lack of understanding of the entire environment.

Anyway what I did notice is that if I copy the line (& "C:\Users\<username>\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression' from C:/Users/<username>/Documents/Powershell/profile.ps1 and place it into (at the end of) %CMDER_ROOT%/config/user_profile.ps1 that conda activate <env name> will work .. however it removes any and all formatting/stylization.

You can achieve the same effect by going to settings >> Startup >> Tasks >> {Powershell::Powershell} and chagning the command from PowerShell -ExecutionPolicy Bypass -NoLogo -NoProfile -NoExit -Command "Invoke-Expression 'Import-Module ''%ConEmuDir%\..\profile.ps1'''" to PowerShell -ExecutionPolicy Bypass -NoLogo -NoProfile -NoExit -Command "Invoke-Expression 'Import-Module ''C:\Users\<username>Documents\Powershell\profile.ps1'''" but again it removes all other styling.

Not sure what that means but I figured I'd give this information out to anyone searching and maybe they can come up with a solution based off of this.