美文网首页
CentOS系统下安装并配置Anaconda

CentOS系统下安装并配置Anaconda

作者: 复苏的兵马俑 | 来源:发表于2020-04-11 22:59 被阅读0次

    1、下载Anaconda

       1)官网源地址:https://www.anaconda.com/distribution/
       2)清华源地址(推荐使用,下载速度快):https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/?C=N&O=D

    [root@server anaconda]# wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.02-Linux-x86_64.sh
    --2020-04-11 21:23:21--  https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.02-Linux-x86_64.sh
    Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
    Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 546910666 (522M) [application/octet-stream]
    Saving to: ‘Anaconda3-2020.02-Linux-x86_64.sh’
    
    100%[====================================================================>] 546,910,666 7.78MB/s   in 80s
    
    2020-04-11 21:24:42 (6.50 MB/s) - ‘Anaconda3-2020.02-Linux-x86_64.sh’ saved [546910666/546910666]
    

    2、安装Anaconda

    [root@server anaconda]# bash Anaconda3-2020.02-Linux-x86_64.sh
    
    Welcome to Anaconda3 2020.02
    
    In order to continue the installation process, please review the license
    agreement.
    Please, press ENTER to continue
    >>>
    ===================================
    End User License Agreement - Anaconda Individual Edition
    ===================================
    Copyright 2015-2020, Anaconda, Inc.
    All rights reserved under the 3-clause BSD License:
    (此处license部分省略……)
    Do you accept the license terms? [yes|no]
    [no] >>> yes
    Anaconda3 will now be installed into this location:
    /root/anaconda3
    
      - Press ENTER to confirm the location
      - Press CTRL-C to abort the installation
      - Or specify a different location below
    
    [/root/anaconda3] >>> /opt/anaconda3
    PREFIX=/opt/anaconda3
    Unpacking payload ...
    Collecting package metadata (current_repodata.json): done
    Solving environment: done
    
    ## Package Plan ##
    
      environment location: /opt/anaconda3
    
      added / updated specs:
        - _ipyw_jlab_nb_ext_conf==0.1.0=py37_0
        - _libgcc_mutex==0.1=main
        - alabaster==0.7.12=py37_0
        - anaconda-client==1.7.2=py37_0
        - anaconda-navigator==1.9.12=py37_0
    (此处省略……)
      zeromq             pkgs/main/linux-64::zeromq-4.3.1-he6710b0_3
      zict               pkgs/main/noarch::zict-1.0.0-py_0
      zipp               pkgs/main/noarch::zipp-2.2.0-py_0
      zlib               pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3
      zstd               pkgs/main/linux-64::zstd-1.3.7-h0b5b093_0
    
    
    Preparing transaction: done
    Executing transaction: done
    installation finished.
    Do you wish the installer to initialize Anaconda3
    by running conda init? [yes|no]
    [no] >>> yes
    no change     /opt/anaconda3/condabin/conda
    no change     /opt/anaconda3/bin/conda
    no change     /opt/anaconda3/bin/conda-env
    no change     /opt/anaconda3/bin/activate
    no change     /opt/anaconda3/bin/deactivate
    no change     /opt/anaconda3/etc/profile.d/conda.sh
    no change     /opt/anaconda3/etc/fish/conf.d/conda.fish
    no change     /opt/anaconda3/shell/condabin/Conda.psm1
    no change     /opt/anaconda3/shell/condabin/conda-hook.ps1
    no change     /opt/anaconda3/lib/python3.7/site-packages/xontrib/conda.xsh
    no change     /opt/anaconda3/etc/profile.d/conda.csh
    modified      /root/.bashrc
    
    ==> For changes to take effect, close and re-open your current shell. <==
    
    If you'd prefer that conda's base environment not be activated on startup,
       set the auto_activate_base parameter to false:
    
    conda config --set auto_activate_base false
    
    Thank you for installing Anaconda3!
    
    ===========================================================================
    
    Anaconda and JetBrains are working together to bring you Anaconda-powered
    environments tightly integrated in the PyCharm IDE.
    
    PyCharm for Anaconda is available at:
    https://www.anaconda.com/pycharm
    

       anaconda在自动初始化过程中会在 ~/.bashrc 文件中写入一些内容,如下:

    [root@server anaconda]# cat ~/.bashrc
    # .bashrc
    
    # User specific aliases and functions
    
    alias rm='rm -i'
    alias cp='cp -i'
    alias mv='mv -i'
    
    # Source global definitions
    if [ -f /etc/bashrc ]; then
            . /etc/bashrc
    fi
    
    # >>> 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 <<<
    

       这时候需要使用命令souce重新load一下该配置文件,可以看到命令提示符前面加了一个(base),如下:

    [root@server anaconda]# source ~/.bashrc
    (base) [root@server anaconda]#
    

       使用命令conda list以验证是否安装成功,如果安装成功会列出所有已经成功安装的包,如下:

    (base) [root@server anaconda]# conda list
    # packages in environment at /opt/anaconda3:
    #
    # Name                    Version                   Build  Channel
    _ipyw_jlab_nb_ext_conf    0.1.0                    py37_0
    _libgcc_mutex             0.1                        main
    alabaster                 0.7.12                   py37_0
    anaconda                  2020.02                  py37_0
    anaconda-client           1.7.2                    py37_0
    anaconda-navigator        1.9.12                   py37_0
    anaconda-project          0.8.4                      py_0
    argh                      0.26.2                   py37_0
    (此处省略)
    yapf                      0.28.0                     py_0
    zeromq                    4.3.1                he6710b0_3
    zict                      1.0.0                      py_0
    zipp                      2.2.0                      py_0
    zlib                      1.2.11               h7b6447c_3
    zstd                      1.3.7                h0b5b093_0
    

       看到上面的信息就说明已经安装成功了。

    3、配置Python默认下载源

       输入python可以看到当前安装的python版本号(这里使用的不是系统自带的python环境),如下:

    (base) [root@server anaconda]# python
    Python 3.7.6 (default, Jan  8 2020, 19:59:22)
    [GCC 7.3.0] :: Anaconda, Inc. on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

       默认是从Python官方下载软件包,但是有的大包下载比较慢,我们可以设置国内下载镜像,我们以清华下载源为例说明:
       1)想要永久设置,需要在用户的根目录下创建一个.pip的隐藏文件夹,然后在里面创建一个pip.conf的文件,如下:

    (base) [root@server anaconda]# cd ~
    (base) [root@server ~]# mkdir .pip
    (base) [root@server ~]# cd .pip/
    (base) [root@server .pip]# vi pip.conf
    

       2)写入镜像源信息,保存并退出,如下:

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    trusted-host = pypi.tuna.tsinghua.edu.cn
    

       至此,Anaconda的安装和配置已经完成。

    相关文章

      网友评论

          本文标题:CentOS系统下安装并配置Anaconda

          本文链接:https://www.haomeiwen.com/subject/zrupmhtx.html