Anaconda
Anaconda
Anaconda 是一个数据科学和机器学习的软件套装,它包含了许多工具和库,能够使我们更加轻松的进行编程、分析数据和构建机器学习模型。而这篇文章主要聚焦如何安装 Anaconda 和利用其中的 conda 环境管理。
安装
下载一个合适版本的安装脚本
1 | curl -O https://repo.anaconda.com/archive/Anaconda3-2024.06-1-Linux-x86_64.sh |
执行安装脚本
1 | bash Anaconda3-2024.06-1-Linux-x86_64.sh |
按 Enter 键查看许可协议,按q结束快速结束内容,最后输入
yes同意协议,然后按 Enter 接受默认安装位置
/home/<USER>/anaconda3 。
最后会问你要不要每次启动都默认激活conda环境
Do you wish to update your shell profile to automatically initialize conda? This will activate conda on startup and change the command prompt when activated. If you’d prefer that conda’s base environment not be activated on startup, run the following command when conda is activated:
conda config –set auto_activate_base false
You can undo this by running
conda init --reverse $SHELL? [yes|no] [no] >>>
我的选择是默认的no(Enter)
1 | conda config --set auto_activate_base false |
随之而来的是自己完成初始化
You have chosen to not have conda modify your shell scripts at all. To activate conda’s base environment in your current shell session:
eval “$(/home/
<username>/anaconda3/bin/conda shell.YOUR_SHELL_NAME hook)”To install conda’s shell functions for easier access, first activate, then:
conda init
Thank you for installing Anaconda3!
例:
1 | eval "$(/home/jiangshun/anaconda3/bin/conda shell.zsh hook) |
最后init
1 | conda init <zsh> |
测试
1 | conda -V |
conda 24.5.0
完成!
换源
1 | vim ~/.condarc |
写入如下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- defaults
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- 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
show_channel_urls: true
保存后退出并执行
1 | conda clean -i |
使用
- 检查虚拟环境
1 | conda env list |
- 创建虚拟环境
1 | 有环境包时 |
- 激活
1 | conda activate env_name |
- 删除虚拟环境
1 | conda remove -n env_name --all |
- 导出当前conda环境:
先激活你要导出的环境 1
conda activate 你的环境名
再导出到 yml 文件
1 | conda env export > environment.yml |
导出后会在当前目录生成 environment.yml
删除
1 | conda install anaconda-clean |
参考资料
博客园.
菜鸟教程.