Windows 中的 Anaconda 和 Git Bash - conda: command not found [英] Anaconda and Git Bash in Windows - conda: command not found

查看:32
本文介绍了Windows 中的 Anaconda 和 Git Bash - conda: command not found的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 Anaconda 并将 Path 环境变量设置为 C:Anaconda3;C:Anaconda3Scripts.

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

然后我尝试在 Git Bash 中运行

Then I try to run in Git Bash

conda 安装 python

但是有一个错误信息bash: conda: command not found".我想知道为什么.

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 with an error like this one:

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: command not found的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆