惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
博客园 - Franky
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
爱范儿
爱范儿
罗磊的独立博客
博客园_首页
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
V
Visual Studio Blog
T
Tailwind CSS Blog

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19)
Conda 安装与使用
微信公众号 · 2024-03-28 · via 陈少文的网站

1. 安装 conda

1
2
3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
rm -rf Miniconda3-latest-Linux-x86_64.sh

但 Miniconda 不能免费大规模商用,可以使用 Miniforge 平替。

1
2
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3-$(uname)-$(uname -m).sh

2. 修改默认配置

2.1 初始化 Shell

如果不进行初始化,激活环境时会报错 CondaError: Run 'conda init' before 'conda activate'

1
2
3
4
5
6
7
8
9
conda init --help

usage: conda init [-h] [--all] [--user] [--no-user] [--system] [--reverse] [--json] [-v] [-q] [-d] [SHELLS ...]

Initialize conda for shell interaction.

positional arguments:
  SHELLS         One or more shells to be initialized. If not given, the default value is 'bash' on unix and 'cmd.exe' & 'powershell' on Windows. Use the '--all' flag to initialize all shells. Available shells: ['bash', 'fish', 'powershell',
                 'tcsh', 'xonsh', 'zsh']

针对不同 Shell 终端,需要执行不同的初始化命令。

  • zsh
  • bash

执行初始化的目的是,让 Shell 启动会话时自动执行 Conda 的初始化脚本、配置环境变量。

2.2 修改 Conda 包存储的位置

  • 编辑 .condarc 文件,添加配置
1
2
3
4
pkgs_dirs:
  - /Volumes/Data2/Conda/packages
envs_dirs:
  - /Volumes/Data2/Conda/environments

这里将默认路径改为 /Volumes/Data2/Conda 目录下,避免占用系统盘空间。

  • 查看配置信息

2.3 使用国内镜像源

  • 编辑 .condarc,添加国内镜像源
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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/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
  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
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/

3. 环境管理

  • 新建环境
1
conda create -n newenv python=3.9
  • 查看环境列表
1
2
3
4
5
6
conda env list

# conda environments:
#
newenv                   /Volumes/Data2/Conda/environments/newenv
base                     /usr/local/Caskroom/miniconda/base
  • 激活环境
  • 退出环境
  • 删除环境
1
conda remove -n newenv --all

4. 包管理

  • 搜索包
  • 安装包
1
conda install pytorch==2.2.0
  • 从指定渠道安装包
1
conda install pytorch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 pytorch-cuda=12.1 -c pytorch -c nvidia

针对国内源找不到的包,可以通过 -c 指定渠道安装。

  • 查看包
  • 更新包
  • 删除包
  • 安装 requirements.txt 包
1
conda install --file requirements.txt