简体   繁体   English

Zsh:未找到 Conda/Pip 安装命令

[英]Zsh: Conda/Pip installs command not found

So I installed Anaconda and everything is working.所以我安装了Anaconda并且一切正常。 After I installed it I decided to switch to oh-my-zsh .安装后,我决定切换到oh-my-zsh I am now getting:我现在得到:

zsh: command not found: conda

when trying to use pip or conda installs尝试使用pipconda安装时

echo $ZSH_VERSION

5.0.5 5.0.5

I have added to my zshenv.sh我已添加到我的zshenv.sh

export PATH ="/Users/Dz/anaconda/bin:$PATH"

What is it that I'm missing?我错过了什么?

I found an easy way.我找到了一个简单的方法。 Just follow below steps:只需按照以下步骤操作:

  1. in terminal, enter vim ~/.zshrc在终端中,输入vim ~/.zshrc 在此处输入图像描述
  2. add source ~/.bash_profile into .zshrc filesource ~/.bash_profile添加到 .zshrc 文件中在此处输入图像描述
  3. and then in terminal, enter source ~/.zshrc然后在终端中,输入source ~/.zshrc 在此处输入图像描述

Congratulation for you!!!恭喜你!!! ㊗️ 🎉🎉🎉 ㊗️🎉🎉🎉

If you are on macOS Catalina, the new default shell is zsh.如果您使用的是 macOS Catalina,则新的默认 shell 是 zsh。 You will need to run source /bin/activate followed by conda init zsh.您将需要运行 source /bin/activate,然后运行 ​​conda init zsh。 For example: I installed anaconda python 3.7 Version, type echo $USER to find username例如:我安装了anaconda python 3.7版本,输入echo $USER查找用户名

source /Users/my_username/opt/anaconda3/bin/activate

Follow by遵从

conda init zsh

or (for bash shell)或(对于 bash shell)

conda init

Check working:检查工作:

conda list

The error will be fixed.错误将得到修复。

As of today Nov 4, 2018 all the following methods works, install the zsh with:截至今天 2018 年 11 月 4 日,以下所有方法都有效,安装 zsh:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Not recommending brew installation for zsh:建议为 zsh 安装 brew:

brew install zsh zsh-completions 

PS: Tried with with brew and brew install under the root and is not an wise idea to do so due the security and all time anything related will need to be started under sudo so better is to stick with curl or wget . PS:尝试在根目录下使用 brew 和 brew install ,但由于安全性和所有相关的时间都需要在 sudo 下启动,这样做并不是一个明智的主意,所以最好坚持使用curlwget

to make work conda in OS X with oh-my-zsh installed is to add path as following and will work.在安装了 oh-my-zsh 的 OS X 中进行工作 conda 是添加如下路径并将工作。

Find the python paths so can see if you installed Anaconda2 or Anaconda3: where python or which python will result in similar output:找到 python 路径,以便查看您是否安装了 Anaconda2 或 Anaconda3: where pythonwhich python将产生类似的输出:

/usr/bin/python
/Users/"username"/anaconda/bin/python # # previous path for anaconda
/Users/"username"/anaconda3/bin/python # # previous path for anaconda3
/Users/"username"/opt/anaconda/bin/python # # for current path anaconda
/Users/"username"/opt/anaconda3/bin/python # # for current path for anaconda3

one line config command:一行配置命令:

echo -e '# >>> anaconda conda config >>> \nPATH="$HOME/opt/anaconda3/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc && conda init

Note: Anaconda do not recommend to add manually paths per following: Should I add Anaconda to the macOS or Linux PATH?注意:Anaconda 不建议按照以下步骤手动添加路径:我应该将 Anaconda 添加到 macOS 还是 Linux PATH?

We do not recommend adding Anaconda to the PATH manually.我们不建议手动将 Anaconda 添加到 PATH。 During installation, you will be asked “Do you wish the installer to initialize Anaconda3 by running conda init?”在安装过程中,系统会询问您“您是否希望安装程序通过运行 conda init 来初始化 Anaconda3?” We recommend “yes”.我们建议“是”。 If you enter “no”, then conda will not modify your shell scripts at all.如果您输入“no”,那么 conda 根本不会修改您的 shell 脚本。 In order to initialize after the installation process is done, first run source /bin/activate and then run conda init.为了在安装过程完成后进行初始化,首先运行 source /bin/activate 然后运行 ​​conda init。

Note:

Replace <path-to-anaconda> with the actual path of your installed Anaconda file.

What is the default path for installing Anaconda?安装 Anaconda 的默认路径是什么?

If you accept the default option to install Anaconda on the “default path” Anaconda is installed in your user home directory:如果您接受在“默认路径”上安装 Anaconda 的默认选项,Anaconda 将安装在您的用户主目录中:

  • Windows 10: C:\Users<your-username>\Anaconda3\ Windows 10:C:\Users<您的用户名>\Anaconda3\

  • macOS: /Users//anaconda3 for the shell install, ~/opt for the graphical install. macOS:/Users//anaconda3 用于 shell 安装,~/opt 用于图形安装。 See installing on macOS .请参阅在 macOS 上安装

  • Linux: /home//anaconda3 Linux:/home//anaconda3

If your username includes spaces, as is common on Windows systems, you should not accept the default path.如果您的用户名包含空格(这在 Windows 系统上很常见),则不应接受默认路径。 See In what folder should I install Anaconda on Windows?请参阅我应该在 Windows 上的哪个文件夹中安装 Anaconda?

I already have Python installed.我已经安装了 Python。 Can I install Anaconda?我可以安装 Anaconda 吗?

You do not need to uninstall other Python installations or packages before installing Anaconda.在安装 Anaconda 之前,您无需卸载其他 Python 安装或软件包。 Even if you already have a system Python, another Python installation from a source such as the macOS Homebrew package manager and globally installed packages from pip such as pandas and NumPy , you do not need to uninstall, remove, or change any of them .即使您已经有一个系统 Python、另一个来自macOS Homebrew包管理器等源的 Python 安装以及来自pip的全局安装包(如pandasNumPy ),您也无需卸载、删除或更改其中的任何一个

Install Anaconda or Miniconda normally.正常安装 Anaconda 或 Miniconda。 There is no need to set the PYTHONPATH environment variable.无需设置PYTHONPATH环境变量。

To see if the conda installation of Python is in your PATH variable:要查看 Python 的 conda 安装是否在您的 PATH 变量中:

  • On macOS and Linux, open the terminal and run echo $PATH .在 macOS 和 Linux 上,打开终端并运行 echo $PATH

  • On Windows, open an Anaconda Prompt and run echo %PATH% .在 Windows 上,打开 Anaconda Prompt 并运行 echo %PATH%

To see which Python installation is currently set as the default:要查看当前设置为默认的 Python 安装:

  • On macOS and Linux, open the terminal and run which python .在 macOS 和 Linux 上,打开终端并运行which python
  • On Windows, open an Anaconda Prompt and run where python .在 Windows 上,打开 Anaconda Prompt 并运行where python

To see which packages are installed in your current conda environment and their version numbers, in your terminal window or an Anaconda Prompt, run conda list .要查看当前 conda 环境中安装了哪些软件包及其版本号,请在终端窗口或 Anaconda Prompt 中运行conda list

For detailed info on adding manually see below info:有关手动添加的详细信息,请参阅以下信息:

Finding your Anaconda Python interpreter path 找到你的 Anaconda Python 解释器路径

vi ~/.zshrc or gedit ~/.zshrc vi ~/.zshrcgedit ~/.zshrc

Anaconda updated to use similar to Anaconda Enterprise edition paths : /opt/... @update Dec 2021: For Anaconda3 at field # User configuration add: Anaconda 更新为使用类似于 Anaconda 企业版路径/opt/... @update Dec 2021:对于字段# User configuration添加的 Anaconda3:

PATH="$HOME/opt/anaconda3/bin:$PATH"

For Anaconda: at field # User configuration add:对于 Anaconda:在字段# User configuration添加:

`PATH="$HOME/anaconda/bin:$PATH"`

For Anaconda2 at field # User configuration add:对于字段# User configuration中的 Anaconda2,添加:

  `PATH="$HOME/anaconda/bin:$PATH"`

For Anaconda3 at field # User configuration add:对于字段# User configuration添加的 Anaconda3:

`PATH="$HOME/anaconda3/bin:$PATH"`

or replace "username" with your username:或用您的用户名替换“用户名”:

`PATH="/Users/"username"/anaconda3/bin:$PATH`

According to documentation Installing on macOS we add add in ~/.zshrc instead of .bashrc or .bash_profile根据在 macOS 上安装的文档,我们添加了~/.zshrc而不是.bashrc or .bash_profile

  • Add export PATH="/<path to anaconda>/bin:$PATH" in ~/.zshrc在 ~/.zshrc 中添加 export PATH="/<path to anaconda>/bin:$PATH"

  • Or set the PATH variable: export PATH="/<path to anaconda>/bin:$PATH"或者设置 PATH 变量: export PATH="/<path to anaconda>/bin:$PATH"

Replace “<path to anaconda>” with the actual path to your Anaconda installation.“<path to anaconda>”替换为 Anaconda 安装的实际路径。

This methods are working on ubuntu/Centos7/MacOS as well (just close/reset the terminal once you are completing the changes) than just type conda to test.此方法也适用于 ubuntu/Centos7/MacOS(完成更改后只需关闭/重置终端),而不仅仅是键入conda进行测试。


Per @truongnm comment just source after adding the path: "I pasted the path from my bash_profile, and don't forget to source ~/.zshrc "每个@truongnm 评论只是添加路径后的来源:“我从我的 bash_profile 粘贴了路径,不要忘记source ~/.zshrc

It appears that my PATH is broken in my .zshrc file.看来我的.zshrc文件中的 PATH 已损坏。

Open it and add :打开它并添加:

export PATH="$PATH;/Users/Dz/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/Dz/.rvm/bin"

Doh!嗬! Well that would explain everything.那么这将解释一切。 How did I miss that little semicolon?我怎么会错过那个小分号? Changed:改变:

export PATH="$PATH:/Users/Dz/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/Dz/.rvm/bin"

source ~/.zshrc
echo $HOME
echo $PATH

We're good now.我们现在很好。

The anaconda installer automatically writes the correct PATH into the ~/.bash_profile file. anaconda 安装程序会自动将正确的 PATH 写入 ~/.bash_profile 文件。 Copy the line to your ~/.zshrc file, source it with source ~/.zshrc and you're good to go.将该行复制到您的 ~/.zshrc 文件中,使用source ~/.zshrc获取它,您就可以开始了。

I had this problem on my Catalina OSX after I installed my Anaconda distribution as well.在我安装了 Anaconda 发行版后,我的 Catalina OSX 也遇到了这个问题。

This solution worked for me on macOS Catalina as of October 19, 2019截至 2019 年 10 月 19 日,此解决方案在 macOS Catalina 上对我有效

Step 1. Check if .bash_profile is available on your home folder, if not:步骤 1. 检查 .bash_profile 在您的主文件夹中是否可用,如果没有:

  • Go to Terminal前往终端
  • Type cd ~/ to go to your home folder (if you are not on your home folder)键入cd ~/转到您的主文件夹(如果您不在主文件夹中)
  • Type touch .bash_profile to create your new file under the your home folder键入touch .bash_profile在您的主文件夹下创建新文件

Step 2. Check if file .zshrc is available on your home folder, if not:步骤 2. 检查文件.zshrc在您的主文件夹中是否可用,如果没有:

  • Go to terminal and type nano ~/.zshrc转到终端并输入nano ~/.zshrc

  • Type in the following line into the newly created .zshrc file: source ~/.bash_profile在新创建的 .zshrc 文件中键入以下行: source ~/.bash_profile

  • Now to save the file in nano just hit ctrl + X .现在要将文件保存在 nano 中,只需点击ctrl + X

  • It will prompt "Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES)?"它将提示“保存修改的缓冲区(回答“否”会破坏更改)?” . . Just type in Y只需输入Y

Step 3. Check if .bash_profile and .zshrc files are created on your home folder.步骤 3. 检查是否在您的主文件夹中创建了 .bash_profile 和 .zshrc 文件。 If yes, in terminal type in source ~/.zshrc如果是,在终端输入source ~/.zshrc

You should do the following:您应该执行以下操作:
1. /home/$USER/anaconda/bin/conda init zsh (or /home/$USER/miniconda3/bin/conda init zsh if you use miniconda) 1. /home/$USER/anaconda/bin/conda init zsh (或者/home/$USER/miniconda3/bin/conda init zsh如果你使用 miniconda)
2. source ~/.zshrc (or just reopen terminal) 2. source ~/.zshrc (或者只是重新打开终端)

Why this answer is better than others?为什么这个答案比其他答案更好?

  • You shouldn't reinvent the wheel: there is already command in conda to activate, all you need to do is to call conda with full path你不应该重新发明轮子:conda 中已经有命令激活,你需要做的就是用完整路径调用 conda
  • Maybe ~/.bash_profile doesn't exist (my case, only ~/.bashrc )也许~/.bash_profile不存在(我的情况,只有~/.bashrc
  • You can have bash-specific config inside ~/.bash_profile您可以在~/.bash_profile中拥有特定于 bash 的配置
  • You don't need manually paste and export any pathes您不需要手动粘贴和导出任何路径

This is all I had to add to add get anaconda working for zsh.这就是我必须添加的所有内容,以添加让 anaconda 为 zsh 工作。

echo ". /anaconda3/etc/profile.d/conda.sh" >> ~/.zshrc
source ~/.zshrc

Answer for macOS 11 (Big Sur) in 2021 2021 年 macOS 11 (Big Sur) 的答案

After installing Anaconda, run:安装 Anaconda 后,运行:

source /opt/anaconda3/bin/activate
conda init zsh

then close and reopen the Terminal window.然后关闭并重新打开终端窗口。 The shell prompt should have a (base) prefix. shell 提示符应该有一个(base)前缀。

NOTE: I found many articles online saying to update the PATH variable, but Anaconda actually recommends against doing so and running the two commands above instead, which they state in their documentation.注意:我在网上发现很多文章都说要更新 PATH 变量,但 Anaconda 实际上建议不要这样做,而是运行上面的两个命令,他们在文档中说明了这一点。

Source 资源

You need to fix the spacing and quotes:您需要修复间距和引号:

export PATH ="/Users/Dz/anaconda/bin:$PATH"

Instead use而是使用

export PATH="/Users/Dz/anaconda/bin":$PATH

If this problem occurs on a mac, then type the following commands:如果在 mac 上出现此问题,请键入以下命令:

source <path to conda>/bin/activate
conda init zsh

This will modify your zshrc accordingly (or create it if it does not exist).这将相应地修改您的 zshrc(或者如果它不存在则创建它)。

This solution comes from the official anaconda doc .该解决方案来自官方anaconda doc

I just ran into the same problem.我刚刚遇到了同样的问题。 As implicitly stated inside the .zshrc-file (in your user-root-folder), you need to migrate the pathes you've already inserted in your .bash_profile, bashrc or so to resolve this.正如 .zshrc 文件(在您的用户根文件夹中)中所暗示的那样,您需要迁移已插入 .bash_profile、bashrc 左右的路径来解决此问题。

Copying all additional pathes from .bash_profile to .zshrc fixed it for me, cause zsh now knows where to look.将所有额外的路径从 .bash_profile 复制到 .zshrc 为我修复了它,因为 zsh 现在知道去哪里找了。

#add path to Anaconda-bin
export PATH="/Users/YOURUSERNAME!!/anaconda3/bin:$PATH"

 #N.B. for miniconda use
export PATH="/Users/YOURUSERNAME!!!/miniconda3/bin:$PATH"

Depending on where you installed anaconda this path might be different.根据您安装 anaconda 的位置,此路径可能会有所不同。

If anaconda is fully updated, a simple "conda init zsh" should work.如果 anaconda 完全更新,一个简单的“conda init zsh”应该可以工作。 Navigate into the anaconda3 folder using使用导航到 anaconda3 文件夹

cd /path/to/anaconda3/ cd /path/to/anaconda3/

of course replacing "/path/to/anaconda/" with "~/anaconda3" or "/anaconda3" or wherever the "anaconda3" folder is kept.当然,将“/path/to/anaconda/”替换为“~/anaconda3”或“/anaconda3”或保留“anaconda3”文件夹的任何位置。

To make sure it's updated, run要确保它已更新,请运行

./bin/conda update --prefix . ./bin/conda 更新 --prefix 。 anaconda蟒蛇

After this, running在此之后,运行

./bin/conda init zsh ./bin/conda 初始化 zsh

(or whatever shell you're using) will finish the job cleanly. (或您使用的任何外壳)将干净地完成工作。

  1. Find the right version of your anaconda找到适合您的anaconda的版本

  2. Put it to ~/.zshrc via command vim ~/.zshrc通过命令vim ~/.zshrc把它放到~/.zshrc /.zshrc

    • Anaconda 2 export PATH="/User/<your-username>/anaconda2/bin:$PATH" Anaconda 2 export PATH="/User/<your-username>/anaconda2/bin:$PATH"
    • Anaconda 3 export PATH="/User/<your-username>/anaconda3/bin:$PATH" Anaconda 3 export PATH="/User/<your-username>/anaconda3/bin:$PATH"
    • Or if you install Anaconda in root directory:或者,如果您在根目录中安装 Anaconda:
    • Anaconda 2 export PATH="/anaconda2/bin:$PATH" Anaconda 2 export PATH="/anaconda2/bin:$PATH"
    • Anaconda 3 export PATH="/anaconda3/bin:$PATH" Anaconda 3 export PATH="/anaconda3/bin:$PATH"
  3. Restart the zsh source ~/.zshrc重启 zsh source ~/.zshrc

I simply added the anaconda3 path to $PATH in .zshrc which did the trick for.我只是在 .zshrc 中将 anaconda3 路径添加到 $PATH 中,这起到了作用。

My environment : Catalina / clean Anaconda install / iTerm / zsh / oh-my-zsh我的环境:Catalina / clean Anaconda install / iTerm / zsh / oh-my-zsh

First locate your conda installation:首先找到你的 conda 安装:

> find ~/ -name 'conda' -print

(on my system: ~/opt/anaconda3/bin/conda) (在我的系统上:~/opt/anaconda3/bin/conda)

Then add that path to PATH in the .zshrc file然后将该路径添加到 .zshrc 文件中的 PATH

export PATH="opt/anaconda3/bin":$PATH

run the following script provided by conda in your terminal:在终端中运行 conda 提供的以下脚本:

source /opt/conda/etc/profile.d/conda.sh - you may need to adjust the path to your conda installtion folder. source /opt/conda/etc/profile.d/conda.sh - 您可能需要调整 conda 安装文件夹的路径。

after that your zsh will recognize conda and you can run conda init this will modify your .zshrc file automatically for you.之后您的 zsh 将识别conda并且您可以运行conda init这将自动为您修改您的 .zshrc 文件。 It will add something like that at the end of it:它会在它的末尾添加类似的内容:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/conda/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/conda/etc/profile.d/conda.sh" ]; then
        . "/opt/conda/etc/profile.d/conda.sh"
    else
        export PATH="/opt/conda/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

source: https://docs.conda.io/projects/conda/en/latest/user-guide/install/rpm-debian.html来源: https ://docs.conda.io/projects/conda/en/latest/user-guide/install/rpm-debian.html

For Linux对于 Linux

  1. Open .bashrc打开.bashrc
  2. Copy the code for conda initialize and paste it to .zshrc file复制conda initialize的代码并将其粘贴到.zshrc文件中
  3. Finally run source .zshrc最后运行source .zshrc

Simply copy your Anaconda bin directory and paste it at the bottom of ~/.zshrc .只需复制您的 Anaconda bin目录并将其粘贴到~/.zshrc的底部。

For me the path is /home/theorangeguy/miniconda3/bin , so I ran:对我来说,路径是/home/theorangeguy/miniconda3/bin ,所以我跑了:

echo ". /home/theorangeguy/miniconda3/bin" >> ~/.zshrc

This edited the ~/.zshrc .这编辑了~/.zshrc Now do:现在做:

source ~/.zshrc

It worked like a charm.它就像一个魅力。

MAC OS Users: MAC 操作系统用户:

  1. brew install anaconda
  2. Add export PATH="/usr/local/anaconda3/bin:$PATH" to top of ~/.zshrcexport PATH="/usr/local/anaconda3/bin:$PATH"添加到~/.zshrc的顶部
  3. source ~/.zshrc OR restart terminal source ~/.zshrc或重启终端

Test it.测试一下。 Bingo Bango.宾果班戈。

  1. Open your ~./bashrc打开你的 ~./bashrc
  2. Find the following code (maybe something similar) that launches your conda:找到以下启动 conda 的代码(可能类似的代码):

    # >>> conda init >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)" if [ $? -eq 0 ]; then
        \eval "$__conda_setup" else
        if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
            . "/anaconda3/etc/profile.d/conda.sh"
            CONDA_CHANGEPS1=false conda activate base
        else
            \export PATH="/anaconda3/bin:$PATH"
        fi fi unset __conda_setup
    # <<< conda init <<<

  1. source ~/.zshrc源〜/ .zshrc
  2. Things should work.事情应该会奏效。

So I discovered that in your ~/.zshrc file, there was a commented line,所以我发现在你的 ~/.zshrc 文件中,有一个注释行,

# If you come from bash you might have to change your $PATH # export PATH=$HOME/bin:/usr/local/bin:$PATH

Just uncomment the export statement and all your previous bash_profile commands will also be there.只需取消注释导出语句,您之前的所有 bash_profile 命令也将在那里。 If that comment does not exist, you can also just add that export statement to .zshrc file.如果该注释不存在,您也可以将该导出语句添加到 .zshrc 文件中。

None of these solutions worked for me.这些解决方案都不适合我。 I had to append bash environment to the zsh :我不得不将bash环境附加到zsh

echo 'source ~/.bash_profile' >> ~/.zshrc

Go to terminal PREFERENCES, then PROFILES tab, then under the STARTUP section within the SHELL tab, check the white boxes for RUN COMMAND and RUN INSIDE SHELL.转到终端 PREFERENCES,然后是 PROFILES 选项卡,然后在 SHELL 选项卡内的 STARTUP 部分下,选中 RUN COMMAND 和 RUN INSIDE SHELL 的白框。 Clear any text in the RUN COMMAND input area, then add the command below and restart the terminal:清除 RUN COMMAND 输入区域中的所有文本,然后添加以下命令并重新启动终端:

source ~/.bash_profile;源〜/ .bash_profile; clear清除

Key is to activate conda after you installed it from executing the official install (eg with sh or something).关键是在您安装 conda 后从执行官方安装(例如使用 sh 或其他东西)激活 conda。 So this:所以这:

source ~/miniconda/bin/activate
conda init zsh

My whole installation:我的整个安装:

# - install python
# install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
#  install wget to get miniconda
brew install wget

# get miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda

# source /Users/my_username/opt/anaconda3/bin/activate
source ~/miniconda/bin/activate
conda init zsh
conda update -n base -c defaults conda
conda install conda-build

conda create -n iit_synthesis python=3.9
conda activate iit_synthesis
#conda remove --name metalearning2 --all

inspired from:灵感来自:

TL;DR TL;博士

Using this script will modify your .zshrc file (which is what we want, but just be warned). 使用此脚本将修改您的.zshrc文件(这是我们想要的,但请注意)。

Anytime you see a file with .*rc it means it is a run command that essentially runs some start up instructions, and in this case, stuff you need for your shell to know so it does what you want it to. 任何时候你看到一个带有.*rc的文件就意味着它是一个运行命令,本质上是运行一些启动指令,在这种情况下,你需要让你的 shell 知道的东西,所以它会做你想做的事。

Assuming you have conda installed already, the following works:假设您已经安装了conda ,以下工作:

$ source path/to/your/conda/activate
(base) $ conda init zsh

For example, the path to my particular conda installation is /Users/username/opt/miniconda3/bin/conda例如,我的特定 conda 安装路径是/Users/username/opt/miniconda3/bin/conda

So my shell commands looked like this:所以我的 shell 命令看起来像这样:

$ /Users/username/opt/miniconda3/bin/conda/activate
(base) $ conda init zsh

Details细节

You type conda into your shell running zsh and it gets mad:您在运行 zsh 的 shell 中键入conda ,它会生气:

$ zsh: command not found: conda

Your zsh shell does not come preconfigured to recognize conda .您的zsh shell 未预先配置为识别conda We know this because there is nothing in your .zshrc file to indicate it knows conda at all.我们知道这一点,因为您的.zshrc文件中没有任何内容表明它完全了解conda You have to tell your shell (in this case zsh ) that you want this to happen.您必须告诉您的 shell (在本例中为zsh )您希望这种情况发生。 The conda team knows this, so they made a command for such a need . conda团队知道这一点,因此他们针对这种需求发出了命令 But, first you have to activate conda manually like you would a virtualenv (don't worry about this last statement if it confuses you).但是,首先您必须像使用virtualenv一样手动激活conda (如果它让您感到困惑,请不要担心最后一条语句)。

So you activate conda manually by using the source command:因此,您可以使用source命令手动激活conda

$ source path/to/your/conda/activate
(base) $

Since paths can differ here, I used a made up path but your path probably looks something like /Users/username/opt/.../activate .由于此处的路径可能不同,因此我使用了一个编造的路径,但您的路径可能类似于/Users/username/opt/.../activate

Next, you run a --dry-run of conda init because you do not want to modify things without knowing what you are modifying (in my opinion).接下来,您运行 conda conda init--dry-run ,因为您不想在不知道自己正在修改什么的情况下进行修改(在我看来)。 An output example is shown below but it may not match yours: output 示例如下所示,但它可能与您的不匹配:

(base) $ conda init zsh --dry-run
no change     /Users/username/opt/miniconda3/condabin/conda
no change     /Users/username/opt/miniconda3/bin/conda
...

If you are happy with what will change, run the same command without the --fry-run flag.如果您对将要更改的内容感到满意,请运行不带--fry-run标志的相同命令。

Finally, restart your shell.最后,重新启动您的 shell。 It should open with something like this:它应该以这样的方式打开:

(base) $

Now you can use conda as you like anytime you start up your shell.现在,您可以在启动 shell 的任何时候随意使用conda

FYI for anyone having this same issue keep in mind that you need to make sure that you have the right version of anaconda in that export path:仅供遇到同样问题的任何人请记住,您需要确保在该导出路径中拥有正确版本的 anaconda:

anaconda2 or anaconda3 

Spent way too long on that minor issue.在那个小问题上花了太长时间。

this solved it for me, and is sure to work add this to ~/.zshrc这为我解决了这个问题,并且肯定可以将它添加到 ~/.zshrc

export PATH=path_to_anaconda_bin:$PATH

the answer答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM