简体   繁体   English

在 macOS Catalina 上将 Anaconda 设置为默认 python

[英]Set Anaconda as default python on macOS Catalina

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.我目前正在使用 Python 迈出第一步,并尝试在我的 mac(macOS Catalania 10.15)上运行 Anaconda 作为 python 的默认选项。 When I type "python" in my terminal though, it is still Python 2.7 that is showing up.但是,当我在终端中键入“python”时,仍然显示的是 Python 2.7。

I found out that in order to run anaconda as a default, I need to customize my.bash_profile.我发现为了默认运行 anaconda,我需要自定义 my.bash_profile。 But as it seems, anaconda is already set there:但似乎 anaconda 已经设置在那里:

# >>> 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.那里的评论指出,从 macOS 10.15 开始,我需要更改 .zprofile。 Unfortunately, I can't find the file.不幸的是,我找不到该文件。

Mac using default Python despite Anaconda install 尽管安装了 Anaconda,但 Mac 使用默认 Python

I would be very greatful if any of you guys could help out!如果你们中的任何人能提供帮助,我将非常感激! René勒内

Catalina by default runs zsh , which you can confirm with echo $0 . Catalina 默认运行zsh ,您可以使用echo $0进行确认。 The file you changed works for bash .您更改的文件适用于bash

Copy the following anaconda init lines to .zshrc and you should be good to go:将以下 anaconda 初始化行复制到 .zshrc,您应该对.zshrc很好:

__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 .关于您的文件的唯一区别是将shell.bash替换为shell.zsh

Most commonly, the installation is fine but you can't see that until you refresh your terminal window.最常见的是,安装很好,但在刷新终端 window 之前,您看不到。 Just close it and open a new one.只需关闭它并打开一个新的。

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

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