KHCheng
KHCheng

Reputation: 681

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

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.

Upvotes: 45

Views: 94895

Answers (9)

Theo Oliveira
Theo Oliveira

Reputation: 385

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

Upvotes: 1

Merk
Merk

Reputation: 311

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.

Upvotes: 1

starriet 차주녕
starriet 차주녕

Reputation: 3908

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.

Upvotes: 22

Hafiz Saifullah
Hafiz Saifullah

Reputation: 11

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.

Upvotes: 0

Hamzah Al-Qadasi
Hamzah Al-Qadasi

Reputation: 9786

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.

Upvotes: 0

dvdgc13
dvdgc13

Reputation: 954

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.

Upvotes: 62

f0lie
f0lie

Reputation: 46

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.

Upvotes: 2

DINA TAKLIT
DINA TAKLIT

Reputation: 8388

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

Upvotes: 12

Nditah
Nditah

Reputation: 1739

For MAC users, do this:

$ echo ". /usr/local/anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc
$ source ~/.bashrc

Upvotes: 0

Related Questions