Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 726
KHCheng Avatar asked Feb 03 '19 08:02

KHCheng


People also ask

Why is conda not recognized as a command?

'conda' is not recognized as an internal or external command, operable program or batch file. You get the Python Anaconda error, 'conda' is not recognized as an internal or external command, operable program or batch file, when the path variable in environment is not set correctly.

How do I run a conda in bash?

for anaconda 4 : bashrc and then copy the path into the file and save it after that you activate the changes using source . bashrc. When I type export PATH=~/anaconda3/bin:$PATH into the terminal and then run conda --version it works fine.

How do I open a conda environment in git 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.

Can you use conda in git bash?

In addition, a dedicated console called Git Bash controls your repositories. For that, today I gonna show you how to add the conda command into the Git Bash to get it all in one python-conda-git bash. This step is easy, you can found how to install it on windows pressing here.


2 Answers

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.

like image 197
dvdgc13 Avatar answered Sep 19 '22 15:09

dvdgc13


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

like image 40
DINA TAKLIT Avatar answered Sep 18 '22 15:09

DINA TAKLIT