在centos7安装anaconda3操作手册

一·Anaconda下载
进入anaconda官方网站下载个人免费版本,网站链接,点击download,选择Linux平台的安装包

在这里插入图片描述

 

二·Anaconda安装


1.执行如下指令,安装anaconda

# 进入当保存文件的目录,执行此指令, 后期由于版本更新,可能会与此文件命名有所不同
bash Anaconda3-2020.11-Linux-x86_64.sh

2.按照安装提示,键入回车

Please, press ENTER  to continue
>>> ENTER


3.安装此版本时,会强制用户看完整个协议,直接一路回车就行,直到看到确认信息

# 输入yes,表示同意安装协议
Do you accept the license terms? [yes|no][no] 
>>> yes
 

4.确认安装路径(可修改,也可以使用自定义)

# 使用默认路径,直接键入回车,使用自定义路径,直接输入安装路径
# 此处使用 /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
在这里插入图片描述
注:安装位置可以在执行安装脚本的时候直接指定,可以这样修改执行内容:

bash Anaconda3-2020.11-Linux-x86_64.sh -p /opt/anaconda3

这样可跳过软件安装路径确认阶段,直接安装到指定目录下。

5.环境变量初始化

# 此处询问是否初始化conda的环境,直接输入yes
 
Do you wish the installer to initialize Anaconda3
by running conda init? 
 
[yes|no][no] >>> yes

 

安装完成

6.初始化时,anaconda将配置写入了~/.bashrc 文件,直接执行

source ~/.bashrc

后即可正常使用了。

7.配置多用户使用

将anaconda初始化时,写入到 ~/.bashrc 文件中的内容复制到 /etc/bashrc 文件中,内容如下(此处仅为示例,请复制本机对应文件中的相应内容)

# >>> 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 <<<
在这里插入图片描述

 

再执行 source /etc/bashrc 指令即可。

三·配置镜像源
1.conda配置镜像源:

使用conda进行安装时,访问的是国外的网络,所以下载和安装包时会特别慢。我们需要更换到国内镜像源地址,这里我更换到国内的清华大学地址。(永久添加镜像)

Windows和Linux 对于conda修改镜像源的方法一样

1)查看anaconda中已经存在的镜像源

conda config --show channels

2)添加镜像源(永久添加)

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

3) 设置搜索时显示通道地址

conda config --set show_channel_urls yes

4)若不想按照上述步骤添加镜像,可使用以下命令直接指定安装时使用的镜像地址(以opencv为例):

conda install opencv -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
 

5)添加完后查看

conda config --show channels
 


2、pip使用国内镜像源

一般在使用conda install安装时会出现包无法找到或者安装失败的情况,此时可以使用pip install来尝试安装(以opencv为例):

pip install opencv

若安装速度过慢可单独指定安装镜像加快安装:

pip install opencv -i https://mirrors.aliyun.com/pypi/simple/

此处列举国内常用pip安装镜像:

清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple/
中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:https://pypi.hustunique.com/
山东理工大学:https://pypi.sdutlinux.org/
豆瓣:https://pypi.douban.com/simple/

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

四·root用户安装的anaconda如何给普通用户使用
服务器里安装了anaconda,结果发现只有root用户才能使用,其他的用户都无法使用conda命令!

【解决方案】

首先,root用户安装anaconda的时候,需要安装在普通用户可以访问的目录下,比如/usr/local、/opt、/home之类的

其次,普通用户登陆后,需要执行以下conda init 使conda的路径等系统环境变量信息写入当前用户的bashrc下

例:

anaconda 装在了 (需要查看anaconda3安装路径)

/opt/anaconda3

普通用户 需要执行

/opt/anaconda3/bin/conda init bash

你需要根据自己的实际情况修改bin之前的目录

普通用户再执行启用配置命令

source ~/.bashrc

然后重新连接SSH (推荐)

或者

即使你没有重新连接ssh也可以通过(没试过)

source activate base

conda activate base

能正常使用conda后,你就可以创建你自己的环境了,例

conda create -n xxx python=3.7

环境会装在home中你的用户文件夹下,可以通过

conda env list

查看对应的地址

以上操作的问题是,那个用户需要使用conda,就需要按以上步骤执行一遍,并没有设置成所有用户都可以调用的方式。

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值