Mamba安装和常用命令
官网:https://mamba.readthedocs.io/en/latest/index.html
安装
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
bash Miniforge3-Linux-x86_64.sh
#将安装目录下的bin路径添加到PATH环境变量中
mamba --version
mamba 1.5.5
conda 23.11.0 # 除了安装好mamba和conda,默认配置了conda的源(安装路径下.condarc 文件,后需换/添加源,可以直接修改此文件)
更换源
vim .condarc # 添加
# 清华源
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/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
ssl_verify: true
# 中科大源
channels:
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
ssl_verify: true
# 上海交大源
channels:
- https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
- https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
- https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/
ssl_verify: true
# 此处同类型的源只需添加一个即可,如果配置多个,会在多个源里进行搜索,一个是结果会重复,第二是命令运行时间长,如果在某个源里没有需要的软件,可以通过“-c”参数,临时指定使用另外一个源。
# 源文件配置方法:https://conda.io/projects/conda/en/latest/userguide/configuration/mirroring.html
常用命令
# 初始化
mamba init # 必须要运行一次,然后重开一个终端,才能 mamba activate/deactivate
# 环境创建
mamba create ( -n name_of_myenv | -p path_of_myenv) -c CHANNEL <list of packages> # -n 或 -p 参数2选1
# 列出所有环境
mamba env list
# 移除环境
mamba env remove -n name_of_myenv
# 搜索软件
mamba search packages_name -c CHANNEL
mamba repoquery search packages_name
# 激活/进入环境
mamba activate name_of_myenv
# 退出环境
mamba deactivate
# 列出当前环境已安装的软件
mamba list
# 安装软件
mamba install packages_name
# 卸载软件
conda remove -n name_of_myenv packages_name
测试
mamba create -p /Software/R/R.4.2.0 r-base=4.2.0 gcc=11.1.0 gfortran=11.1.0 libgcc-ng=13.1.0
WARNING: A directory already exists at the target location '/Software/R/R.4.2.0'
but it is not a conda environment.
Continue creating environment (y/[n])? y
Looking for: ['r-base=4.2.0', 'gcc=11.1.0', 'gfortran=11.1.0', 'libgcc-ng=13.1.0']
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pk.. No change
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pk.. No change
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pk.. No change
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cl.. No change
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pk.. No change
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cl.. No change
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cl.. No change
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cl.. No change
Could not solve for environment specs
The following packages are incompatible
├─ gfortran 11.1.0** is installable and it requires
│ └─ gfortran_linux-64 11.1.0.* , which can be installed;
└─ r-base 4.2.0** is not installable because it requires
└─ gfortran_linux-64 10.* , which conflicts with any installable versions previously reported.
# 看来不同软件对依赖软件的版本有要求,不能无脑装
# 最后的环境创建命令
mamba create -p /Software/R/R.4.2.0 r-base=4.2.0 gcc=10.4.0 gfortran=10.4.0 libgcc-ng=13.1.0
# 测试R并安装包
mamba activate /Software/R/R.4.2.0
R
install.packages('tidyverse', repos='https://mirrors.tuna.tsinghua.edu.cn/CRAN/')
# 第一次偷懒,直接使用路径/Software/R/R.4.2.0/bin/R 启动R 并安装包,会报错:
/bin/sh: x86_64-conda-linux-gnu-c++: command not found
# 等包安装好了以后可以直接这样启动R
# ERROR: dependency ‘ragg’ is not available for package ‘tidyverse’
install.packages("ragg", repos='https://mirrors.tuna.tsinghua.edu.cn/CRAN/')
# ft_cache.h:9:10: fatal error: ft2build.h: No such file or directory
# 9 | #include <ft2build.h>
# | ^~~~~~~~~~~~
yum install fontconfig-devel.x86_64
# 安装ragg 再次报错
# ERROR: dependency ‘textshaping’ is not available for package ‘ragg’
mamba install r-textshaping
#mamba install freetype-devel libpng-devel libtiff-devel libjpeg-devel
yum install -y freetype-devel libpng-devel libtiff-devel
# 安装libjpeg-devel
yum install libjpeg-turbo-devel
# 继续报错
/Software/R/R.4.2.0/bin/../lib/gcc/x86_64-conda-linux-gnu/10.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: cannot find -lpng15: No such file or directory # 需要安装libpng15-devel
# 下载 https://jaist.dl.sourceforge.net/project/libpng/libpng15/1.5.30/libpng-1.5.30.tar.gz
tar -xzvf libpng-1.5.30.tar.gz
cd libpng-1.5.30
make && make install # 安装完之后软链进环境里的lib文件夹里,或者直接安装在当前环境的lib文件夹里(/Software/R/R.4.2.0/lib)
# 再次安装ragg包,安装成功
# 再次安装tidyverse包,安装成功,真是费劲
其他
- 默认关闭bsea环境:conda config --set auto_activate_base false