CentOS 7安装Anaconda3_Python_缘崖西轩-CSDN博客

获取Anaconda安装脚本

访问Anaconda官网下载页面,右键点击你想要安装的版本,复制链接地址。写这个的时候最新Anaconda版本是5.3.1,所以我获取到的安装脚本文件是Anaconda3-5.3.1-Linux-x86_64.sh,以下都以这个版本来讲述。

更新:最近再阿里云上直接访问官网的下载链接比较忙,然后我就换了清华大学的源。安装脚本的下载地址可以在这里找。也可以直接替换官网地址中repo.anaconda.com的为mirrors.tuna.tsinghua.edu.cn/anaconda。Anaconda 镜像替换参考这里

执行下面的命令讲执行脚本获取到本地:

wget https://repo.anaconda.com/archive/Anaconda3-5.3.1-Linux-x86_64.sh

解决安装WARNINTG

我是用的阿里云上直接安装的CentOS7,安装Anaconda的时候提示“WARNING: bzip2 does not appear to be installed this may cause problems below”,最开始我忽视了这个提示,于是安装的时候提示错误:“No package bunzip2 available.”。执行yum install bzip2,重新安装就好了。

基于上面的教训建议大家关注下这样的WARNING,及时解决。

安装Anaconda

通过执行bash Anaconda3-5.3.1-Linux-x86_64.sh可以进行Anaconda的安装。安装过程中有5处需要我们进行交互的,下面一一说来。

安装过程中如果要退出,可以随时按Ctrl+C退出安装程序。

第一次:提示你接下来是许可协议

这次不用输入任何东西,直接回车继续安装过程。

Welcome to Anaconda3 5.3.1

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

第二次:输入yes确认接受许可协议

许可协议其实蛮长的,会有多页。如果没看到让你输入的地方,并且末行显示--More--,可以按Z键翻页,或者按Q跳到最后。

直到显示如下,输入yes后回车:

Do you accept the license terms? [yes|no]
[no] >>> yes

第三次:确认Anaconda的安装位置

Anaconda的安装位置默认会在执行用户的home目录下的anaconda3目录中,如果是要给服务器的全部用户安装的话,建议大家改成个公共的位置(如果安装时没有添加-u,目录如果存在会报错)。下面我是给改成安装在/opt/anaconda3下了。

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

其实安装位置可以在执行安装脚本的时候直接指定,像上面要指定安装到/opt/anaconda3目录下,可以这样修改执行内容:bash bash Anaconda3-5.3.1-Linux-x86_64.sh -p /opt/anaconda3,这样这一步就可以直接回车了。

执行完这一步后,就会开始安装程序了。安静等待几分钟。

第四次:修改.bashrc脚本讲Anaconda目录添加到PATH中

安装完成后,会出现询问是否在用户(我用的root用户安装的)的.bashrc文件中初始化Anaconda3的相关内容。

Do you wish the installer to initialize Anaconda3
in your /root/.bashrc ? [yes|no]
[no] >>> yes

更新:安装2019版本的时候显示成了:

Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes

但是行为还是一致的。

添加的内容如下:

# >>> 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"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup

添加的内容主要是把conda添加到PATH中,让你能使用conda命令,所以这个可以直接yes。

第五次:询问是否安装Microsoft VSCode

我是云服务器上部署的,自然直接no掉了。

===========================================================================

Anaconda is partnered with Microsoft! Microsoft VSCode is a streamlined
code editor with support for development operations like debugging, task
running and version control.

To install Visual Studio Code, you will need:
  - Administrator Privileges
  - Internet connectivity

Visual Studio Code License: https://code.visualstudio.com/license

Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]
>>> no

安装完成后

安装完成后,直接输入conda应该会提示说没找到该命令,这时候执行下:source ~/.bashrc,之后就可以正常使用了。

配置其他用户可用

为了让其他用户也能使用conda,我们可以将安装脚本添加到.bashrc文件中内容添加到/etc/bashrc中。内容大致是下面这个样子的:

# added by Anaconda3 5.3.1 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"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/opt/anaconda3/bin:$PATH"
    fi
fi


Original url: Access
Created at: 2020-03-27 11:23:22
Category: default
Tags: none

请先后发表评论
  • 最新评论
  • 总共0条评论