
centos 安装 anaconda3
1、查看 anaconda版本
conda -V
conda 4.10.3
2、安装
第一步:下载安装包
这个链接,可以查看anaconda版本
https://repo.continuum.io/archive/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ (推荐,清华大学开源软件镜像站进行下载并配置镜像))

- 下载清华源
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh
报错
--2022-04-21 10:09:34-- https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2021.11-Linux-x86_64.sh
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... connected.
ERROR: cannot verify mirrors.tuna.tsinghua.edu.cn's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
Issued certificate has expired.
To connect to mirrors.tuna.tsinghua.edu.cn insecurely, use `--no-check-certificate'.
发现 是我们的服务器上的CA证书没有更新
Let’s Encrypt 根证书过期,导致pip使用清华镜像不信任 - 教程资源|网络资源 - 如有乐享
yum update ca-certificates -y
之后就可以啦。
- 从其他网址下载
wget https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh
成功下载后
第二步:安装命令
sh Anaconda3-2021.11-Linux-x86_64.sh
不断回车或yes即可
部分过程如下所示

第三步:验证
使用
conda -v
说没有这个命令,
进入默认安装目录 /root/anaconda3 查看

命令未成功,可进行环境变量配置
输入编辑命令:vim /root/.bashrc 或者 vim ~/.bashrc
添加:export PATH="/root/anaconda3/bin:$PATH"
添加以下内容:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/root/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/root/anaconda3/etc/profile.d/conda.sh" ]; then
. "/root/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/root/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<

刷新环境变量:
source ~/.bashrc
但是之后,执行Python,直接进入到anaconda内的Python环境啦,原有的Python3.6环境不起作用啦。糟心!
经过后来测试发现,重新打开 ~/.bashrc ,将刚添加的那个删除掉。
第二个问题:centos 安装Anacond后,打开服务器就进入base状态,不爽!
解决安装Anaconda后默认进入base环境
将auto_activate_base参数设置为false
conda config --set auto_activate_base false
常用
设置anaconda 进入linux,默认进入其中一个环境
要在Linux系统中设置Anaconda默认进入特定的环境,可以通过修改.bashrc或.bash_profile文件来实现。以下是基本步骤:
- 打开
.bashrc或.bash_profile文件,可以使用文本编辑器如vim或nano。
vim ~/.bashrc
或者
vim ~/.bash_profile
- 在文件末尾添加以下行,将Anaconda的环境激活命令添加到文件中,替换
your_environment_name为您要默认进入的环境名称。
conda activate your_environment_name
your_environment_name==py38
保存并关闭文件。
重新启动终端或执行以下命令使更改生效:
source ~/.bashrc
或者
source ~/.bash_profile
现在,每次打开终端时,Anaconda会自动激活您指定的默认环境。
Miniconda 安装
# Miniconda是一个 免费的 轻量级的 conda安装程序
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh
# 2.配置环境变量
vim ~/.bashrc
export PATH="/root/miniconda3/bin:$PATH"
# 为了使修改的 ~/.bashrc 文件生效
source ~/.bashrc
# 3.验证
[root@localhost home]# conda -V
conda 24.1.2
# 4. 禁止 用户登录后 自动激活base环境,可执行如下命令
conda config --set auto_activate_base false
# 实例
[root@localhost home]# conda create -n py38 python=3.8
# 设置进入系统就是py38环境
# 打开~/.bashrc 添加以下命令
conda activate 3.8
# 为了使修改的 ~/.bashrc 文件生效
source ~/.bashrc
3、使用
之后可以根据自己项目的需求,每个项目都创建一个虚拟环境.
创建一个项目的虚拟环境
conda create -n py38 python=3.8

然后,你可以conda env list 查看是否有你新加的;
[root@iz2zejf0fjkrh3aalbiatoz ~]# conda env list
# conda environments:
#
base * /root/anaconda3
py38 /root/anaconda3/envs/py38
[root@iz2zejf0fjkrh3aalbiatoz ~]# conda activate py38
(py38) [root@iz2zejf0fjkrh3aalbiatoz ~]# python
Python 3.8.13 (default, Mar 28 2022, 11:38:47)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
# 退出当前虚拟环境
(py38) [root@iz2zejf0fjkrh3aalbiatoz ~]# conda deactivate
[root@iz2zejf0fjkrh3aalbiatoz ~]#
删除一个项目的虚拟环境
conda remove -n 环境名 --all
报错1:'Would you like conda to send this report to the core maintainers?'
和公司网络有关
解决办法
conda clean -i
报错2:An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent......
解决办法
把以下这段代码复制到这个.condarc文件中:
vim ~/.condarc
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
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/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
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