Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mac使用默认Python,尽管安装了Anaconda_Python_Macos_.bash Profile_Anaconda_Conda - Fatal编程技术网

Mac使用默认Python,尽管安装了Anaconda

Mac使用默认Python,尽管安装了Anaconda,python,macos,.bash-profile,anaconda,conda,Python,Macos,.bash Profile,Anaconda,Conda,我正在运行Mac10.9Mavericks并安装了Anaconda。然而,尽管如此,当我通过终端访问python时,我仍然得到默认的Apple版本: Python 2.7.5 (default, Sep 2 2013, 05:24:04) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin 我的.bash_档案如下: export PATH="$HOME/anaconda/bin:$PATH" MONGO_PA

我正在运行Mac10.9Mavericks并安装了Anaconda。然而,尽管如此,当我通过终端访问python时,我仍然得到默认的Apple版本:

Python 2.7.5 (default, Sep  2 2013, 05:24:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
我的.bash_档案如下:

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

MONGO_PATH=/usr/local/mongodb/bin
SQL_PATH=/usr/local/mysql

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
我可以做些什么来使用蟒蛇版本的Python吗?此刻不知所措


谢谢

第一个匹配的可执行文件就是运行的可执行文件。据我所知,您正在以如下方式连接PATH变量:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
先到:

$HOME/anaconda/bin
因此确保anaconda目录是第一个目录,这意味着它将具有优先级

export PATH="$HOME/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"

如果您使用LiClipse或Eclipse作为IDE,那么Preferences菜单将使这个管理过程变得更加容易。但我理解命令行的乐趣

让Anaconda,或者说Anaconda的Python版本成为LiClipse中的默认解释器,以及从Anaconda调用站点包,非常容易。我今天刚准备好

问候,


JF

如果您使用的是zsh,您可以在根文件夹中的zshrc文件中编辑以包括

export PATH="$HOME/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"

如果您使用的是fish,则可以将Anaconda备份旧的.bash_配置文件为.bash_profile-Anaconda.bak,并在.bash_配置文件底部添加了两行,如下所示:

# added by Anaconda2 4.1.1 installer
export PATH="/Users/username/anaconda/bin:$PATH"
但是fish不会读取它,因此您必须手动将其添加到fish配置文件中,该文件位于~/.config/fish/config.fish中:

set -x PATH /Users/username/anaconda/bin $PATH

确保您使用的是完整路径: -不要使用“~”而不是根:

(错)

(正确)


这个改变对我有用

更新对于所有看到Python 3的人来说:上述解决方案不适用于Python 3

巨蟒的Python 3现在位于
~/anaconda3/bin
。因此,我们应该:

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


对于较新版本的mac OS,anaconda现在安装在~/opt/anaconda下。如果您有my zsh,请执行以下步骤:

  • vim.bash_profile=>这里您应该在底部看到这些注释
  • 将这些注释之间的所有内容添加到.zshrc文件的底部,然后重新启动终端

  • 使用OSX10.15,安德烈的回答对我来说很有效(在愤怒地搜索了一个小时之后)

    下面是保存上述步骤的文本块:

    # >>> conda init >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$(CONDA_REPORT_ERRORS=false '/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"  # commented out by conda initialize
            CONDA_CHANGEPS1=false conda activate base
        else
            \export PATH="/opt/anaconda3/bin:$PATH"
        fi
    fi
    unset __conda_setup
    # <<< conda init <<<
    
    #>>康达初始化>>>
    # !! 此块中的内容由“conda init”管理!!
    __conda_setup=“$(conda_REPORT_ERRORS=false'/opt/anaconda3/bin/conda'shell.bash hook 2>/dev/null)”
    如果[$?-等式0];然后
    \评估“$\uuu conda\u设置”
    其他的
    如果[-f”/opt/anaconda3/etc/profile.d/conda.sh“;然后
    # . “/opt/anaconda3/etc/profile.d/conda.sh”#由conda initialize注释掉
    CONDA_CHANGEPS1=假CONDA激活基
    其他的
    \导出路径=“/opt/anaconda3/bin:$PATH”
    fi
    fi
    未设置条件设置
    
    #如果您的默认shell是sh(或者可能不是bash),那么您将无法访问anacondapython。如果这是您的情况:

  • 转到终端/首选项
  • 查找“打开的壳:”
  • 单击“命令(完整路径)”按钮
  • 键入
    /bin/bash
    作为路径
  • 重新启动终端。当您键入
    $whichpython
    时,现在应该可以看到蟒蛇。对我来说是
    /Users/myname/anaconda3/bin/python

    $echo$PATH
    现在也将更改为显示正确路径,首先显示蟒蛇:

    /Users/myname/anaconda3/bin:/Users/myname/anaconda3/condabin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin

    在Atom中,我必须在每个脚本的开头添加一个shebang,以将其设置为我的首选项:
    #/Users/myname/anaconda3/bin/python

    路径是从左到右搜索的,所以第二个路径设置对第一个没有好处。注意:自从Mac OS 10.15 Catalina以来,苹果将默认shell从bash更改为zsm。对于较新操作系统上的读者,请在
    .zprofile
    (或
    .zshrc
    )而不是
    .bash profile
    中进行这些更改。谢谢!工作起来很有魅力。“我真蠢,没想到这是个好办法。”。如果我们想“撤消”此操作并恢复到使用默认安装,该方法是什么?@Pyderman删除添加的“导出路径”行就足够了。在我的mac上,anaconda不在
    $HOME/anaconda
    ,,但是在
    //anaconda
    ^下,如果提供的其他解决方案没有将ananconda二进制文件添加到路径中,这通常是另一种情况。这对我很有效!奇怪的是,在到达anaconda python版本时存在终端类型依赖。。这是为什么?我在这里的第3/4步无意中编辑了路径,但无法确定路径是什么。也就是说,我更改了终端设置中显示的路径。然后,我无法运行我的python脚本,因为终端默认返回到MacOS默认,MacOS默认没有我的任何包,仍然是2.7版本。这对我有用!谢谢,太棒了!到处寻找。不,@Chris的答案在Python 3中对我有用。
    export PATH="$HOME/anaconda3/bin:$PATH"
    
    export PATH="$HOME/anaconda3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
    
        added by Anaconda3 2019.10 installer
    
    # >>> conda init >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$(CONDA_REPORT_ERRORS=false '/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"  # commented out by conda initialize
            CONDA_CHANGEPS1=false conda activate base
        else
            \export PATH="/opt/anaconda3/bin:$PATH"
        fi
    fi
    unset __conda_setup
    # <<< conda init <<<