超算平台使用miniforge安装conda环境
单位使用的超算平台从去年某时间起不提供统一管理的 anaconda 环境,本文介绍如何在超算平台使用 miniforge 安装 conda 环境。
背景
Anaconda 在 2024 年 3 月 31 日 生效的服务协议中新增了对组织使用的具体要求,原文如下:
2.1 Organizational Use. Your registration, download, use, installation, access, or enjoyment of all Anaconda Offerings on behalf of an organization that has two hundred (200) or more employees or contractors (“Organizational Use”) requires a paid license of Anaconda Business or Anaconda Enterprise. For sake of clarity, use by government entities and nonprofit entities with over 200 employees or contractors is considered Organizational Use. Purchasing Starter tier license(s) does not satisfy the Organizational Use paid license requirement set forth in this Section 2.1. Educational Entities will be exempt from the paid license requirement, provided that the use of the Anaconda Offering(s) is solely limited to being used for a curriculum-based course. Anaconda reserves the right to monitor the registration, download, use, installation, access, or enjoyment of the Anaconda Offerings to ensure it is part of a curriculum. Utilizing Miniconda to pull package updates from the Anaconda Public Repository without a commercial license (if required by the conditions set forth in Section 2 of this Terms of Service) is considered a violation of the Terms of Service.
使用 ChatGPT 翻译如下:
2.1 组织使用
若您代表拥有二百(200)名及以上雇员或承包人员的组织注册、下载、使用、安装、访问或以其他方式使用任何 Anaconda 产品或服务(以下简称“组织使用”),则须依据本条款取得 Anaconda Business 或 Anaconda Enterprise 的有效付费许可。 为避免歧义,政府机关及雇员或承包人员数量超过二百(200)人的非营利组织的使用,同样应视为组织使用。
购买 Starter 级别许可产品,并不足以满足本条第2.1款所规定之组织使用付费许可要求。
教育机构可豁免前述付费许可要求,前提条件是其对 Anaconda 产品或服务的使用限于基于课程设置的教学活动。Anaconda 有权对 Anaconda 产品或服务的注册、下载、使用、安装、访问或其他使用行为进行监控,以核实该等使用是否确属课程教学之需要。
若在未依法取得商业许可(且根据本服务条款第2条之规定需取得商业许可的情形下),使用 Miniconda 从 Anaconda 公共仓库获取软件包更新,视为违反本服务条款的行为,Anaconda 有权依据相关规定追究责任。
根据上述服务协议,超过 200 名团队使用 Anaconda 需要取得付费许可,也就意味着单位的超算平台无法免费使用 Anaconda 旗下的各种产品,包括
- Anaconda Distribution
- Conda
- Miniconda
- …
ECMWF 也提供了移除 Anaconda 和 Miniconda 依赖的说明文档。
实际上,数值天气预报模式业务系统使用的 Python 环境通常安装来自 conda-forge 中的软件包,而 conda-forge 本身属于开源组织。 只需使用没有版权风险的类 conda 命令,就可以将无缝迁移 Python 环境。
conda-forge 组织维护 miniforge 项目,提供 conda 和 mamba 命令,是 Anaconda conda 命令的开源替代,该项目使用开源协议 BSD-3-Clause,没有版权风险。
安装conda环境
从官方网站 https://conda-forge.org/download/ 下载 Linux X86 版本的安装文件 (shell脚本形式):
https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
上传到超算平台个人目录中,设置可执行权限,并运行。
出现如下提示时,输入安装 miniforge3 的目录,因 g1 分区空间较小,建议设置到 WORKDIR 对应的目录中。 为了演示,下面提示中使用了 JOB_TMP 目录。
Miniforge3 will now be installed into this location:
/g1/u/wangdp/miniforge3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/g1/u/wangdp/miniforge3] >>> /g7/JOB_TMP/wangdp/miniforge3
经过一段安装过程后,会提示是否为当前 shell 自动启动 conda。 建议按照默认选项选择 no,等使用时手动激活 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
选择 no 后,会提示如何激活 conda 环境
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 "$(/g7/JOB_TMP/wangdp/miniforge3/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 Miniforge3!
为了在 bash 中激活 conda 环境,创建 start_miniforge3.sh,写入上述代码:
eval "$(/g7/JOB_TMP/wangdp/miniforge3/bin/conda shell.bash hook)"
加载该脚本,就可以激活 conda 环境:
[wangdp@login_a11 /g7/JOB_TMP/wangdp]$. start_miniforge3.sh
(base) [wangdp@login_a11 /g7/JOB_TMP/wangdp]$
安装Python库
可以使用 CMA 的 PyPi 镜像 安装 Python 包。 比如安装 numpy 库
pip install numpy -i http://pypi.mirrors.cma.cn:8080/root/pypi/+simple/ --trusted-host pypi.mirrors.cma.cn
测试 numpy 库是否正常安装
(base) [wangdp@login_a11 /g7/JOB_TMP/wangdp]$python
Python 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.arange(0, 20)
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19])
后记
Anaconda 清华源在 2019 年某段时间内停止服务,后来又恢复服务,参见清华源发布的新闻:
- 2019.4.16 关于停止Anaconda镜像服务的通知
- 2019.6.15 Anaconda 镜像即将恢复
- 2019.7.21 Anaconda 相关镜像已恢复
上述三个新闻均提到类似的说法:
请有意愿架设 Anaconda 镜像站(包括成为 TUNA 下游)的个人及团体注意,根据 Anaconda 软件源上的说明,Anaconda 和 Miniconda 是 Anaconda, Inc. 的商标,任何未经授权的公开镜像都是不允许的。
也就是同步清华 Anaconda 镜像提供公开使用也必须得到 Anaconda 授权才行。
前文提到的 ECMWF 迁移 Anaconda 环境文档中给出了三种方案:
本文介绍的方法属于第三种方案。
第二种方案可以参看另一篇博文《使用Modulefile加载Conda环境》。
笔者后续将尝试第一种基于容器的方案。
参考
Moving away from Anaconda and Miniconda by ECMWF
关于 Anaconda 协议的介绍可以参考如下文章:
Understanding Anaconda’s Upcoming Licensing Changes in 2024
相关博文: