Windows中的Anaconda和Git Bash-conda:找不到命令 [英] Anaconda and Git Bash in Windows - conda: command not found
问题描述
我已经安装了Anaconda,并将Path环境变量设置为C:\Anaconda3; C:\Anaconda3\Scripts
.
I've installed Anaconda and set Path environment variable to C:\Anaconda3; C:\Anaconda3\Scripts
.
然后我尝试在Git Bash中运行
Then I try to run in Git Bash
conda install python
但是有一条错误消息"bash:conda:找不到命令".我想知道为什么.
But there is an error message "bash: conda: command not found". I would like to know why.
推荐答案
要在gitbash上运行conda,您需要将其添加到路径中.很多时候,我已经看到默认情况下是这样做的-如本次研讨会的设置中所示.如果不是这样(如您所愿),则可以通过运行以下命令直接运行其设置:
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
运行后,您应该能够运行conda命令.
After running that you should be able to run conda commands.
要永久保留此设置,您可以在.profile
或.bashrc
文件中添加这样的行(详细了解它们的区别).一种方法是运行以下操作:
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
如果安装Anaconda的路径包含空格(例如 ,C:\Program Files
),则可能会遇到问题.在这种情况下,您将需要更改anaconda的位置或使用以下内容编辑conda.sh
脚本:
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
此sed命令插入一个新的别名定义myconda
,该别名定义将anaconda路径从Program Files
更改为Program\ Files
,因此bash不会停止以下错误:
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 whit an error like:
bash: /c/Program: No such file or directory
第二个sed命令用创建的新别名替换_CONDA_EXE
变量.
The second sed command replaces the _CONDA_EXE
variable by the new alias created.
由于上述操作并未修改anaconda提供的文件,因此,您将需要更新.profile
文件以加载我们刚刚创建的文件conda_start.sh
.
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.
这篇关于Windows中的Anaconda和Git Bash-conda:找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!