9

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.

NeeX
  • 91
  • 1
  • 3
  • Possible duplicate of [Anaconda and Git Bash in Windows - conda: command not found](https://stackoverflow.com/questions/54501167/anaconda-and-git-bash-in-windows-conda-command-not-found) – Simba Oct 15 '19 at 08:54
  • 1
    Thanks @Simba . But I actually have `conda` in my path. I call `conda --version` and the bash displays conda's information successfully. – NeeX Oct 15 '19 at 10:31
  • 5
    I had the same problem. I renamed my ```.bash_profile``` to ```.bashrc``` and it worked – Auss Mar 20 '20 at 08:32
  • @Auss this worked for me, can you explain why? – CatsLoveJazz Jul 17 '20 at 07:55
  • https://superuser.com/questions/183870/difference-between-bashrc-and-bash-profile helped me. – Auss Jul 17 '20 at 14:17
  • 1
    @Auss Unless you know what these files already contain, it is better to copy .bash_profile to .bashrc instead of renaming it. These are files sourced in different occasions and it might cause an issue in the future with interactive login or similar – laxris Sep 29 '20 at 20:20

4 Answers4

6

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
hugovdberg
  • 1,461
  • 13
  • 24
  • I did as explained in this solution, but that was not enough for me. I had to do the following as well: 1. Open git bash AS ADMIN 2. $ conda init bash - This seemed to modify this file: C:\ProgramData\anaconda3\etc\profile.d\conda.sh After that I can use the following command successfully in VS Code (in new bash terminal): $ conda activate – freenrg Jun 02 '23 at 11:55
5

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.

adeli
  • 51
  • 1
  • 3
  • In my case, I had 2 instances of Git Bash with 2 different home directories. Copying both files to both "home" directories made both instances work correctly with conda – Tom Wagstaff May 04 '23 at 10:36
0

Adding this line to .bash_profile solved it:

. /c/Anaconda3/etc/profile.d/conda.sh

(See answer to this related question for more information)

Burrough Clarke
  • 522
  • 4
  • 19
0

Only usefull for a handfull of people:

conda init requires bash behind it. So use conda init bash or any other shell name. Stupid mistake but simple fix.