Reputation: 111
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?
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.
Upvotes: 11
Views: 13605
Reputation: 1
In Git Bash, type:
conda init bash
Open up ~/.bash_profile
in an editor, for me it is under C:\Users\MyUserName.bash_profile, notice that Conda
has now appended a few lines to it
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
if [ -f '/c/ProgramData/anaconda3/Scripts/conda.exe' ]; then
eval "$('/c/ProgramData/anaconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
fi
# <<< conda initialize <<<
So now, using an editor, open up and copy the lines into ~/.bashrc
.
After that, refresh the bash session by doing
source ~/.bashrc
Then proceed to activate the Conda
environment.
conda activate the_name_of_the_env
Upvotes: 0
Reputation: 610
In my case simply typing conda init bash
in git bash shell
solved the problem.😉
Upvotes: 2
Reputation: 99
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.
Upvotes: 0
Reputation: 532
Adding this line to .bash_profile solved it:
. /c/Anaconda3/etc/profile.d/conda.sh
(See answer to this related question for more information)
Upvotes: 0
Reputation: 51
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.
Upvotes: 5
Reputation: 1631
For me there were two problems:
conda init
creates a .bash_profile
file with the correct initialisation, but git-bash.exe
loads .bashrc
(thanks to Auss' comment)C:\Users\<username>\.bash_profile
and bash needs ~/.bashrc
, but ~/
was not equal to C:\Users\<username>\
.My solution was to
code ~/.bashrc
from the git terminal in VS Code to make sure the .bashrc
is created in the right locationC:\Users\<username>\.bash_profile
and paste into the opened .bashrc
Upvotes: 11