Anaconda and Git Bash in Windows - conda: command not found
Asked Answered
N

9

43

I've installed Anaconda and set Path environment variable to C:\Anaconda3; C:\Anaconda3\Scripts.

Then I try to run in Git Bash

conda install python

But there is an error message "bash: conda: command not found". I would like to know why.

Natashianatassia answered 3/2, 2019 at 8:33 Comment(2)
type: echo $PATH in your git bash and double check if your git bash see the paths you just added. For instanse my git bash gives me something like: /c/Anaconda3/condabin:/c/Anaconda3/Scripts:/c/Anaconda3:Coenzyme
discuss.codecademy.com/t/setting-up-conda-in-git-bash/534473Vaporimeter
U
58

To be able to run conda on gitbash you need to add it to the path. Many times I've seen that's done by default - as shown in the setup for this workshop. If it doesn't, as it seems your case, then you can run their setup directly by running:

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

After running that you should be able to run conda commands.

To keep this setup permanently you can add such line on your .profile or .bashrc file (read more about their differences). A way of doing so is running the follwing:

echo ". /c/Anaconda3/etc/profile.d/conda.sh" >> ~/.profile

You may encounter problems if the path where Anaconda was installed contains spaces (e.g., C:\Program Files). In that case you would need to change the anaconda location or edit conda.sh script with something like:

sed -e '/^_CONDA_EXE=.*/a alias myconda="${_CONDA_EXE/ /\\\\ }"' \
    -e 's/\$_CONDA_EXE/myconda/g' /c/Program\ Files/Anaconda3/etc/profile.d/conda.sh > conda_start.sh

This sed command inserts a new alias definition myconda which changes the anaconda path from Program Files to Program\ Files so bash doesn't stop with an error like this one:

bash: /c/Program: No such file or directory

The second sed command replaces the _CONDA_EXE variable by the new alias created.

Since the above doesn't modify the file provided by anaconda, you will need to update your .profile file to load the file we've just created, conda_start.sh, instead.

Unreserve answered 16/5, 2019 at 13:52 Comment(6)
note: ~/.profile may not be read if ~/.bashrc or ~/.bash_login exists.Endbrain
I am running into the same issue here. I have followed these instructions, but I get a new error: conda bash: C:\bld\conda_1565126647711_h_env\Scripts\conda.exe: No such file or directory. I have no idea why this path is: C:\bld\conda_1565126647711_h_env\!! When I looked further I noticed that the 'conda activate' bash script at ~\Anaconda3\Scripts\activate, and within the script I have this variable: _CONDA_ROOT="C:\bld\conda_1565126647711_h_env"! I think it has issues with the virtual envs. I have tried to modify that path to my actual Anaconda path, but does not work, any ideas??Eliseoelish
I think my solution above may not be up to date anymore. If you installed a new version of Anaconda, and checked "Add anaconda to my PATH environment variable" during its instalation, then I believe you can run conda init bash from a git bash terminal. This will create an entry to your .bash_profile. In your case, I think the difference between where you have your conda installation and your environments may be giving your troubles. Are your "virtual envs", anaconda environments?Unreserve
Note the "\ " trick to include a path with spaces does work inside the echo command too! No need for the sed command.Paralysis
fmorenovr.medium.com/…Vaporimeter
discuss.codecademy.com/t/setting-up-conda-in-git-bash/534473Vaporimeter
A
21

First, you need to move to the directory where conda is located.

(some path such as C/Anaconda3/Scripts or ../miniconda3/Scripts or anaconda3/bin)

then, open the terminal.

(or, if you use Windows and can't find where the conda is, try moving to directory such as C:\Users\User_Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit) and open the Anaconda prompt.)

Then, do this:

conda init

(or, put ./ such as ./conda init)

or something like

conda init bash

(or ./conda init bash)

if you use Mac OS:

conda init zsh

will work well.

if you wanna use different shell,

conda init [shell_name]

[shell_name] can be: bash, cmd.exe, fish, powershell, tcsh, xonsh, zsh, etc.

use conda init --help for more info.

Admeasurement answered 21/8, 2020 at 3:14 Comment(3)
I don't see how this can work. The OP said the "conda" command is not found.Akkadian
You just need to work out where the conda executable is and use the full path. So in this case, it's \C\Anaconda3\Scripts\conda init bash.Fisken
STEP BY STEP: - switch to ../miniconda3/Scripts/ - open git bash in folder - ./conda init bash - This willl change .bash_profile file.Thorvaldsen
B
12

Joining @dvdgc13. In my case, I fixed the problem by adding

. C:/Users/user/Anaconda3/etc/profile.d/conda.sh

to my .bash_profile.

enter image description here

Baccy answered 16/5, 2020 at 4:43 Comment(0)
L
2

I tried to do the same thing as you did but I couldn't get it to work. starriet had the working answer but I am going to make it easier for everyone else reading. You can directly open command windows with explorer instead of struggling with paths.

  1. Find your Anaconda3 folder with Windows Explorer This could be a user install where would be in your user folder such as "C:/Users/your_name/Anaconda3".

  2. Shift + Right Click on the explorer and click on "Open PowerShell Windows Here". Note: you can just click "Git Bash" and you open Bash instead which makes no difference to the command.

Shift+Right Click

  1. Type in "conda init" in the PowerShell window. This works even if you don't have the right paths because the command line looks for the right exe in the current dictionary. If you scroll down in the explorer, you should be able to find it.

My PowerShell window would look a little different than yours because of my prompt but it makes no difference. PowerShell window

  1. Exit the PowerShell and open Git Bash. Type "conda" to confirm that things work.
Litigable answered 16/7, 2021 at 21:37 Comment(0)
N
1

In my case I upgrade the answer from Dina just using Regex

. C:/\Users/\user/\Anaconda3/\etc/\profile.d/\conda.sh

and then

source ~/.profile
Nasia answered 19/1 at 21:8 Comment(0)
O
0

For MAC users, do this:

$ echo ". /usr/local/anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc
$ source ~/.bashrc
Obscurant answered 18/1, 2020 at 12:57 Comment(1)
The question clearly states that this is about Windows. But I am sure this still helps some lost mac users ;)Ursala
H
0

I tried many ways, but they are incomplete until I run the following commands:

  1. Go to the path of anaconda3 is C:\Users\USER_NAME\anaconda3 and open commend line over there and print the following: (YOUR_PATH = C:\Users\USER_NAME\anaconda3 )

    echo 'export PATH="$PATH:[YOUR_PATH]:[YOUR_PATH]/Scripts"' >> .bashrc
    echo 'alias python="winpty python.exe"' >> .bashrc
    
  2. If Git bash is opened, close it and reopen it again and type the following to make sure anaconda and python work without problems:

    conda --version 
    python -- version 
    

If you see the versions are printed, everything works well.

Herminiahermione answered 4/11, 2022 at 11:12 Comment(0)
R
0

In my case conda command was recognised in cmd, but not in bash. I used conda init bash instead of simple conda init in cmd. This command modified the .bash_profile file, which was residing in my C:\Users\xyz directory, and added the following code in it

# >>> conda initialize >>>

# !! Contents within this block are managed by 'conda init' !!
eval "$('/C/Users/Saifullah/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
# <<< conda initialize <<<

now it is working in bash terminal too.

Roncesvalles answered 18/12, 2022 at 9:4 Comment(0)
C
0

For me all the above did not work, but I got it working by fixing the path. In the .bash_prfile the following path was inserted: /cygdrive/c/Users/Username/Anaconda3/Scripts/conda.exe

I changed it to C:\Users\UsernameAnaconda3\Scripts\conda.exe and conda could be found by the bash.

Claudication answered 8/8, 2023 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.