Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

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

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...