micromamba 工作环境配置

528 字
3 分钟
micromamba 工作环境配置

之前用的 miniconda,近期看到了 mamba 这个项目,看了下官网,有个 micromamba 的基于 C++ 开发的,性能会更好一些。

micromamba is a fully statically-linked, self-contained, executable. This means that the base environment is completely empty. The configuration for micromamba is slightly different, namely all environments and cache will be created by default under the MAMBA_ROOT_PREFIX environment variable. There is also no pre-configured .condarc/.mambarc shipped with micromamba (they are however still read if present).

micromamba 的特点:

  1. 使用多线程下载 repository data 和 packages(最新的 conda 也支持多线程了);
  2. mamba 使用 libsolv 加速解决依赖关系;
  3. mamba 的核心部分通过 C++ 实现,以获得最大执行效率;
  4. mamba 可与 conda 完美兼容;

homebrew 方式安装#

Terminal window
brew install micormamba

linux 安装#

Terminal window
"${SHELL}" <(curl -L micro.mamba.pm/install.sh)

初始化配置#

Terminal window
mkdir -p ~/micromamba
# 与 zsh 集成
micromamba shell init -s zsh -p ~/micromamba
source ~/.zshrc

配置清华源#

Terminal window
cat >> ~/.condarc << EOF
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/
EOF
# 清除索引缓存
micromamba clean -i
# 和conda不一样,使用 micromamba 必须手动设置channels
micromamba config prepend channels conda-forge

micromamba 可以识别 conda 的配置文件 micromamba 的配置优先级为 API >> CLI >> ENV >> RC 多个 RC 配置文件的读取顺序如下,越晚读到的配置优先级越高

// on_unix
{
"/etc/conda/.condarc",
"/etc/conda/condarc",
"/etc/conda/condarc.d/",
"/etc/conda/.mambarc",
"/var/lib/conda/.condarc",
"/var/lib/conda/condarc",
"/var/lib/conda/condarc.d/",
"/var/lib/conda/.mambarc"
}
// on_win
{
"C:\\ProgramData\\conda\\.condarc",
"C:\\ProgramData\\conda\\condarc",
"C:\\ProgramData\\conda\\condarc.d",
"C:\\ProgramData\\conda\\.mambarc"
}
{ root_prefix }/.condarc
{ root_prefix }/condarc
{ root_prefix }/condarc.d
{ root_prefix }/.mambarc
~/.conda/.condarc
~/.conda/condarc
~/.conda/condarc.d
~/.condarc
~/.mambarc
{ target_prefix }/.condarc
{ target_prefix }/condarc
{ target_prefix }/condarc.d
{ target_prefix }/.mambarc
$CONDARC,
$MAMBARC;

使用 micromamba#

操作命令示例

Terminal window
micromamba create --name <env_name>
micromamba activate <env_name>
micromamba install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia
Terminal window
# 创建新环境
micromamba create -n [email protected] python=3.12
# 激活环境
micromamba activate [email protected]
# 取消激活环境
micromamba deactivate
# 删除环境
micromamba env remove -n [email protected]

安装 pandas 测试

Terminal window
micromamba install pandas

Untitled 17
Untitled 17

vscode集成配置#

在安装的时候,如果没有修改默认的设置,则mamba的路径应该在~/micromamba

打开VSCode的设置,添加下面的设置:

  • python.venvFolders这一项,添加mamba的目录名,即micromamba
    image 47
    image 47
  • python.venvPath这一项,添加mamba虚拟环境的目录,即~/micromamba/envs
    image 48
    image 48
  • Python:select interceptor选择指定解释器
    image 49
    image 49

📎 参考文章#

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

micromamba 工作环境配置
https://blog.sephy.top/posts/micromamba-environment-configuration/
作者
虾米
发布于
2024-04-23
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
虾米
coder
分类
标签
最新动态

还没有发布动态

更多动态
站点统计
文章
63
动态
0
分类
5
标签
57
总字数
67,972
运行时长
0
最后活动
0 天前
站点信息
构建平台
GitHub Actions
博客版本
Firefly v6.14.2
文章许可
CC BY-NC-SA 4.0