3

I am currently making my first steps with Python and try to get Anaconda running on my mac (macOS Catalania 10.15) as my default option for python. When I type "python" in my terminal though, it is still Python 2.7 that is showing up.

I found out that in order to run anaconda as a default, I need to customize my .bash_profile. But as it seems, anaconda is already set there:

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

I found this question that seems to solve the same problem, but I am not sure how to apply the solution of it to my problem. A comment there states, that starting with macOS 10.15 I need to change the .zprofile. Unfortunately, I can't find the file.

Mac using default Python despite Anaconda install

I would be very greatful if any of you guys could help out! René

Rene
  • 33
  • 3
  • If you don't have file then you can create one by just typing `sudo nano ~/.zprofile` or sometimes it uses `sudo nano ~/.zsh`(this works in mycase). – Jay Patel Feb 20 '21 at 19:43
  • I have written a blog long time back for students, in which i show them how to add something in your `bash profile` or `zsh`. You can refer [this](https://github.com/patel999jay/Bellhop-ARLPY-ECED6575/blob/master/MacOS%20Installation%20Manual.pdf) for more details – Jay Patel Feb 20 '21 at 19:46
  • @JayPatel: Thank you! I created the file with ´´´´sudo nano ~/.zsh´´´´and it works! Thanks alot! – Rene Feb 21 '21 at 11:41

2 Answers2

1

Catalina by default runs zsh, which you can confirm with echo $0. The file you changed works for bash.

Copy the following anaconda init lines to .zshrc and you should be good to go:

__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup

The only difference with respect to your file is replacement of shell.bash with shell.zsh.

Lukasz Tracewski
  • 10,794
  • 3
  • 34
  • 53
  • Thank you for your help Lukasz! I couldn't find the file so I created it as described here: https://superuser.com/questions/886132/where-is-the-zshrc-file-on-mac I pasted in the initialization, but still I get Python 2.7 as default. Could it be that I installed Anaconda for all users and not just myself? Do I have to change something so the .zshrc gets checked? Thanks your help! – Rene Feb 20 '21 at 22:46
  • @Rene It should work for all users, including yourself. I think the issue was with the fact that the code snippet was using `shell.bash` and it should `shell.zsh`. I edited my answer to reflect that. Shout if that did not work. Perhaps obvious, but you need to either start a new terminal or restart shell after making any edit to `.zshrc`. And yes, you did the right thing with creating the file. Have you confirmed that indeed you are running `zsh` with `echo $0`? – Lukasz Tracewski Feb 21 '21 at 09:20
  • @Rene I am glad it worked. Can you accept this as the answer then? Thanks. – Lukasz Tracewski Feb 22 '21 at 13:39
  • @LukaszTracewski Great answer, works great. – ABC May 09 '21 at 18:44
0

Most commonly, the installation is fine but you can't see that until you refresh your terminal window. Just close it and open a new one.

John
  • 1,018
  • 12
  • 19