Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conda init doesn't work in bash on Windows

I install Git-Bash and conda on my Windows, which provides two program: C:\Program Files\Git\git-bash.exe and C:\\Program Files\\Git\\bin\\bash.exe.

The latter, C:\\Program Files\\Git\\bin\\bash.exe, does not work with conda properly. When I try to conda acitvate base, I get a message:

Administrator@##### MINGW64 /bin
$ conda --version
conda 4.7.12

Administrator@##### MINGW64 /bin
$ conda activate base

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.

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

I tried conda init and conda init bash, then close and re-open the bash.exe, but it just remains the same.

Any idea on how to fix the problem?

Possible work around:

I am concerned with this issue because VSCode's Integrated Terminal uses it. I tried to use C:\Program Files\Git\git-bash.exe as Integrated Terminal, but it opens a new window, instead of 'Integrated' in VSCode.

The git-base.exe works fine with conda, so guides on how to setup git-base.exe as VSCode Integrated Terminal is also acceptable.

Any help would be appreciated.

like image 516
NeeX Avatar asked Oct 15 '19 06:10

NeeX


People also ask

How do I run a conda in bash?

In order to make the conda command available in Git Bash, you need to add conda's shell script to your . bashrc file. This is the same file that you store your bash aliases in (such as the sqlite3 alias you probably created when you followed these instructions). Open this folder, then navigate to etc -> profile.

How do you activate conda's base environment in your current shell session?

you can simply add the anaconda bin folder (eg.: ~/anaconda3/bin ) to the system PATH and then source activate ENV_NAME in your ~/. bashrc or ~/.

What does conda SH do?

sh script, and tells it to automatically run the entire script (in batch mode) instead of stopping to ask us questions as it goes. This will create a new directory where the conda program will be located, and also where all of the software that we will eventually install with conda will be stored.


2 Answers

For me there were two problems:

  1. conda init creates a .bash_profile file with the correct initialisation, but git-bash.exe loads .bashrc (thanks to Auss' comment)
  2. My bash home directory was not equal to my windows home directory. Conda created C:\Users\<username>\.bash_profile and bash needs ~/.bashrc, but ~/ was not equal to C:\Users\<username>\.

My solution was to

  • run code ~/.bashrc from the git terminal in VS Code to make sure the .bashrc is created in the right location
  • copy the contents of C:\Users\<username>\.bash_profile and paste into the opened .bashrc
  • Reopen the Git terminal
like image 176
hugovdberg Avatar answered Sep 30 '22 09:09

hugovdberg


Append the configuration in .bash_profile to the .bashrc file

conda init bash
cat ~/.bash_profile >> ~/.bashrc 

conda activate $ENVNAME should work after a bash restart.

like image 30
adeli Avatar answered Sep 30 '22 08:09

adeli