60

I installed Anaconda via command line. The bash file.

If Im in bash, I can open and use anaconda, like notebooks, ipython, etc.

If I change my shell to ZSH, all the anaconda commands appear like "not found".

How I can make it work in zsh?

I use a Mac with OSx Sierra.

starball
  • 20,030
  • 7
  • 43
  • 238
marz
  • 831
  • 1
  • 7
  • 12

14 Answers14

147

Altough I cannot test it on a Mac, (I have a Linux Zsh installed) this should work for you as well: Just execute

/(your conda installation path)/bin/conda init zsh

and restart your zsh shell. The init command will change your ~/.zshrc file accordingly, setting your PATH correctly and slightly change the PS1 (which is was most answers here do manually...).

Sebastian Thees
  • 3,113
  • 4
  • 14
  • 23
  • 22
    I can confirm that this solution works in MacOS. This is in my opinion the easiest and cleanest solution – Ben2209 Dec 04 '19 at 06:10
  • 2
    That's actually what is recommended in their [docs](https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html#using-with-fish-shell) just replace `fish` with `zsh` or your desired shell. – Bernardo Duarte Dec 11 '19 at 19:20
  • 2
    It seems that anaconda will now activate and show the default environment "base", all i wanted was to get the anaconda bin into my path. – Moulde Feb 07 '20 at 13:07
  • Worked for me. My anaconda3 installation was in ~/opt/anaconda3 – thereistonsonenotany Jun 17 '20 at 23:50
  • 1
    Worked like charm in macOS. best and cleanest solution – kannandreams Oct 09 '20 at 17:56
  • @Moulde I also simply wanted to have conda as another option to my pip installation in `/Library/Frameworks` - so, I had to add aliases to `.zshrc` – braulio Jan 18 '21 at 21:56
  • 1
    actually, if one wants conda as a second option to another installation, using `conda config --set auto_activate_base false` turns off the auto activate, thus when you open a new shell, conda distribution is not active by default – braulio Jan 18 '21 at 22:17
  • 2
    This is the best solution so far – Ryoji Kuwae Neto May 23 '21 at 18:31
  • `conda init --help` shows you could do a `conda init --all -d` to do a dry run on seeing what shells it would try to update, and `conda init --all` to actually do the work. – Dave X Aug 01 '21 at 15:26
  • 3
    @marz this should be the 2022's accepted answer... – JPCF Jan 09 '22 at 14:55
  • 1
    After sifting through countless failed solutions, this one finally fixed the problem for me. Thank you. – Kyle Feb 12 '22 at 00:04
  • I agree with @JPCF: this is the right way for 2022+. Additionally, if you're on an m1 mac and still having trouble, see [this thread](https://stackoverflow.com/questions/66296640/how-to-install-anaconda-through-home-brew-m1-mac/66296716#66296716) – BLimitless Dec 31 '22 at 05:45
50

I had a similar issue.

I checked in my .profile, .bashrc, and .bash_profile dot files in order to find any PATH information that I could copy over into my .zshrc file. Sure enough:

# added by Miniconda3 4.2.12 installer
export PATH="/Users/username/miniconda3/bin:$PATH"

After running source ~/.zshrc with those lines added, I could fire up my jupyter notebook server.

Jonathan Wheeler
  • 2,539
  • 1
  • 19
  • 29
  • 1
    @marz as temporary solution, you could active bash environment by typing `source .bashrc` and then go back to "oh my zsh" environment by typing `source zshrc` command. after that conda will work perfect. or you can fire single commnad `source .bashrc && source .zshrc` – chudasamachirag Aug 30 '19 at 05:50
  • on MacOS, this worked for me by adding the line you have to my `~/.bash_profile`, even though it wasn't there in the first place. – Joseph Farah Nov 04 '20 at 04:36
16

This worked for me on my macOS

https://medium.com/@sumitmenon/how-to-get-anaconda-to-work-with-oh-my-zsh-on-mac-os-x-7c1c7247d896


Open the .bash_profile file using:

open ~/.bash_profile

There’s a block of code the anaconda installer added to the end of the file. Copy that.

Mine looks something like this:

# added by Anaconda3 5.3.0 installer
# >>> 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 <<<

Now open your .zshrc file:

open ~/.zshrc

paste the copied code at the end and save it. Then RUN the below command,

source ~/.zshrc

When on iterm2 or the terminal, you should see a (base) pop up in there

veeresh d
  • 71
  • 1
  • 6
Vincent Tang
  • 3,758
  • 6
  • 45
  • 63
15

Since conda 4.4.0 (released 2017-12-20), the recommended way to add conda to your PATH has changed. Instead of the approach described in Jonathan's answer, this should be done using the conda.sh script in the etc/profile.d/ folder of your conda installation. After that you can activate the base environment. More information on why this is the case can be found in the conda changelog.

I needed to add the following lines to my .zshrc:

.  ~/miniconda3/etc/profile.d/conda.sh
conda activate base

This assumes that (mini)conda was installed with default parameters, i.e. into the home folder.

m00am
  • 5,910
  • 11
  • 53
  • 69
10

Following up on @m00am's answer, as of Anaconda 4.5.11, the bash code Anaconda adds to .bashrc seems to run perfectly well also in zsh, so copying that into your .zshrc works well. In my case, the code looked like this:

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

If you stumbled here after that you changed your terminal from bash to zsh because you upgraded macOS from Sierra to Catalina, a slight change from Sebastian Thees's answer will make the job.

First, switch back to bash with

chsh -s /bin/bash

where your old conda environments are all nicely active. Then, activate conda on zsh with

conda init zsh

and finally switch back to zsh with

chsh -s /bin/zsh

No fuss in tracking your conda installation folder this way, which is a plus for a memory-less person like myself.

  • I think this would be better voted, it doesn't rely on manual editing init files... In my case, I just evoked /bin/bash directly, used 'conda init zsh' and closing/reopening terminal have done all magic. Thank you. – mano2a0c40 Mar 20 '21 at 15:16
  • Glad that it was of help! – davide chiuchiu' Mar 22 '21 at 07:59
  • You can avoid the shell switching thing if you call your conda explicitly. I tried a `~/anaconda3/bin/conda init zsh` and it worked for me. – Dave X Aug 01 '21 at 15:20
10

Directly from the Anaconda Installation Documentation:

If you are on macOS Catalina, the new default shell is zsh. You will instead need to run:

source <path to conda>/bin/activate

followed by:

conda init zsh

Unfortunately for some reason, this is only mentioned in the command line install section. If you had installed from GUI you still need to do this.

user2415706
  • 932
  • 1
  • 7
  • 19
4

This solution worked for me on macOS Mojave

If you use version 2019.03 of Anaconda you can update your .zshrc file with

# Anaconda
. /anaconda3/etc/profile.d/conda.sh
conda activate base

after saving file don't forget to run source ~/.zshrc.

After upgrading to Catalina

If you install a new Anaconda3 2019.07 you can use solution below.

open ~/.bash_profile

Copy the line starts with # added by Anaconda3 2019.07 installer and ends with # <<< conda init <<< and paste into .zshrc. Then run source ~/.zshrc.

abdullahselek
  • 7,893
  • 3
  • 50
  • 40
  • this is the correct way to do things for [Anaconda >= 4.4](https://www.anaconda.com/how-to-get-ready-for-the-release-of-conda-4-4/) – James Mertz Jun 11 '19 at 15:33
  • I got: toly@Tolys-MacBook-Pro-4 ~ % source ~/.zshrc source: no such file or directory: /Users/toly/.zshrc. What should I do? – Toly Oct 29 '19 at 16:18
  • Do you have oh-my-zsh installed on your machine https://github.com/robbyrussell/oh-my-zsh – abdullahselek Oct 29 '19 at 20:22
  • When i copy the anaconda block into .zshrc, and run source ~/.zshrc my terminal changes to (base) as it seems to activate the default anaconda environment called base. All I'm trying to do is be able to run jupyter via zsh terminal. I fixed it by changing adding "export PATH="/Users/USERNAME/opt/anaconda3/bin:$PATH"" in my .zshrc – Moulde Feb 07 '20 at 13:10
4

From their docs (This worked for me): If you are on macOS Catalina, the new default shell is zsh. You will instead need to run source <path to conda>/bin/activate followed by conda init zsh.

For my specific installation (Done by double clicking the installer), this ended up being source /opt/anaconda3/bin/activate

Bobby Battista
  • 1,985
  • 2
  • 17
  • 27
1

You need to set your path variable for the ZSH environment. The easy way to do this would be to set your path variable in your .zshrc file to include the location of Anaconda. To get the path in your bash terminal type which anaconda

You can also check this out from http://unix.stackexchange.com

Zsh/Bash startup files loading order (.bashrc, .zshrc etc.)

Community
  • 1
  • 1
Peter Hornsby
  • 4,208
  • 1
  • 25
  • 44
0

in my original profile, which is .bash_profile, it looks like this:

### added by Anaconda3 4.4.0 installer
export PATH="/Users/myname/anaconda/bin:$PATH"

and now i open the file .zshrc, add the sentence above to it, it goes all right now.

Haoyu Guo
  • 1
  • 1
0

I had a similar issue after I installed anaconda3 in ubuntu.

This is how I solved it:

1) I changed to bash and anaconda can work

2) I changed to zsh, and anaconda works. I don't know why, but I think you can try.

Sanip
  • 1,772
  • 1
  • 14
  • 29
0

In .bashrc

zsh

In .zshrc

conda activate base

all exports should be resolved

only if you do not use chsh

0

Had this problem while installing conda with brew on mac M1/M2. adding paths in the ~/.zshrc didint work either, so I uninstalled conda with brew install anaconda and then installed conda from the official website and it worked. No need to add any env vars or any thing in this approach.

Amir nazary
  • 384
  • 1
  • 7