0%

Conda环境配置

安装Anaconda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
wget https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh

sudo chmod +x Anaconda3-2024.10-1-Linux-x86_64.sh # 文件添加执行权限

sudo sh Anaconda3-2024.10-1-Linux-x86_64.sh # 执行安装

# Please, press ENTER to continue -> 回车继续
# 阅读协议,同意按回车(跳过ctrl+c)
# Do you accept the license terms? [yes|no] -> 同意协议输入yes回车
# Anaconda3 will now be installed into this location -> 选择安装路径(本文安装/usr/local/anaconda3),等待安装
# by running conda init? [yes|no] -> 是否添加系统环境,输入yes回车
# 待安装结束

# 刷新当前用户环境(激活环境)
source /usr/local/anaconda3/bin

如果是否添加环境变量选择no的话,安装完成需要手动添加环境变量

1
2
export ANACONDA3_ROOT=/usr/local/anaconda3
export PATH=$ANACONDA3_ROOT/bin:$ANACONDA3_ROOT/condabin:$PATH

如果安装时选择了no但安装完成还想初始化可以执行

1
2
source /usr/local/anaconda3/bin/activate
conda init

![[Anaconda环境配置/IMG-20250326093704426.png]]

安装完成后查看.bashrc 中变更内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/usr/local/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/usr/local/anaconda3/etc/profile.d/conda.sh" ]; then
. "/usr/local/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/usr/local/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<

解决打开终端Anaconda自启动问题

1
2
3
4
```
#### 镜像源

北京外国语大学

channels:

Anaconda添加删除虚拟环境

1
2
3
4
5
# 新建虚拟环境 -n 为新建虚拟环境命名
conda create -n python310 python=3.10

# 删除虚拟环境
conda remove -n python310 --all

Anaconda切换虚拟环境

1
2
3
4
5
6
7
8
# 查看所有虚拟环境
conda env list

# 激活虚拟环境
conda activate python310

# 退出虚拟环境
conda deactivate python310