Conda 构建包与特定的 python 版本兼容

Abr*_*don 2 python python-3.x conda

我正在尝试创建一个 conda 包,它应该与大于或等于 3.7 的所有 python 版本兼容。

我在我的conda.recipe/meta.yaml

requirements:
  host:
    - python >=3.7
    - pip
  run:
    - python >=3.7
    - importlib-resources >=1.4.0
    - ...
Run Code Online (Sandbox Code Playgroud)

对于我的构建命令,我首先激活了 Python 3.7 conda 环境,然后指定构建命令应使用相同的环境,并且为了安全起见,我还指定构建命令应使用 Python 3.7:

$ CONDA_ENV=/path/to/py3.7/conda/env
$ conda create --yes -p $CONDA_ENV python=3.7 conda-build conda-verify importlib-resources>=1.4.0 # ...remaining reqs
$ conda activate $CONDA_ENV
$ conda build --python=3.7 -p $CONDA_ENV /path/to/package/dir
Run Code Online (Sandbox Code Playgroud)

中的构建步骤conda.recipy/meta.yaml也使用相同的环境:

build:
  script: bash -c 'source ~/.bashrc && conda activate /path/to/py3.7/conda/env && python -m pip install --no-deps --ignore-installed -vv /path/to/package/dir'
Run Code Online (Sandbox Code Playgroud)

问题

运行上述命令会创建此文件:

my-package-1.1.0-py310_0.tar.bz2
Run Code Online (Sandbox Code Playgroud)

我不明白为什么py310在包名称中,我做了我能想到的一切来使其与 3.7 兼容。

以下是当我尝试使用 python 3.7 和我创建的包创建环境时发生的情况(将 tar.bz2 文件上传到我的 conda 存储库后):

$ conda create -p ~/temp/conda python=3.7 my-package
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed

UnsatisfiableError: The following specifications were found to be incompatible with each other:

Output in format: Requested package -> Available versions

Package python conflicts for:
python=3.7
my-package -> python[version='>=3.10,<3.11.0a0']
my-package -> importlib-resources[version='>=1.4.0'] -> python[version='2.7.*|3.5.*|3.6.*|>=2.7,<2.8.0a0|>=3.8,<3.9.0a0|>=3|>=3.6|>=3.7|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.5,<3.6.0a0|3.4.*|>=3.9,<3.10.0a0|3.10.*']
The following specifications were found to be incompatible with your system:

  - feature:/linux-64::__glibc==2.27=0
  - feature:|@/linux-64::__glibc==2.27=0

Your installed version is: 2.27
Run Code Online (Sandbox Code Playgroud)

但是,如果我在创建环境时不指定 3.7,它可以正常工作,但会创建一个使用 3.10 的环境。

$ conda create -p ~/temp/conda python my-package
Run Code Online (Sandbox Code Playgroud)

问题

如何兼容my-packagePython 3.7?

Abr*_*don 5

经过大量徒劳的研究和无休止的试验和错误,我发现我应该通过添加noarch: python到我的 meta.yaml 来使我的包不特定于任何 python 版本:

build:
  noarch: python
  script: bash -c 'source ~/.bashrc && conda activate /path/to/py3.7/conda/env && python -m pip install --no-deps --ignore-installed -vv /path/to/package/dir'
Run Code Online (Sandbox Code Playgroud)