Python 封装 : Creating a dependency on a `conda-forge` package in `conda` `meta.yaml` file

标签 python conda gdal conda-forge conda-build

我正在为 conda-forge 编写一个包,需要指定对另一个 conda-forge 依赖项的依赖项。本质上,我需要安装 conda-forge gdal 包的固定版本,因为它实际上编译了支持 BIGTIFF 文件的 libtiff 版本......
现在,如果我将 gdal 安装到 conda 环境中,我会写类似的东西。

conda install -c conda-forge gdal=2.4.4 
我会在安装包时从 gdal=2.4.4 安装这个版本的 conda-forge。现在在 meta.yaml 文件中,我可以像这样指定包依赖项,但我没有看到如何指定 tar 文件的 URL,或者其他任何可行的方法。
{% set version = "0.0.1" %}

package:
  name: mypackage
  version: {{ version }}

source:
  url: https://github.com/myrepo/{{ version }}.tar.gz
  sha256: ****6a63

build:
  number: 1
  skip: true  # [win and py27]
  entry_points:
    - mycli = mypackage.main:main

requirements:
  build:
    - python
    - 
  host:
    - python
    - pip
    - numpy
    - gdal  # <----- want to specify from conda-forge
  run:
    - python
    - gdal  # <----- want to specify from conda-forge
任何有关如何做到这一点的建议将不胜感激。

最佳答案

我认为不可能在 meta.yaml 中指定 channel 。 conda-build 问题跟踪器中的以下问题仍未解决:
https://github.com/conda/conda-build/issues/532
作为一种解决方法,如果您知道所需的 gdal 的确切版本,则可以在配方中指定确切的版本和“构建字符串”。
唯一令人讨厌的是,您必须为您的配方需要支持的平台和 python 版本的每个组合列出一次 gdal

requirements:
  build:
    - python
    - 
  host:
    - python
    - pip
    - numpy
    - gdal  2.4.4 py36h02fde04_1  # [osx and py==36]
    - gdal  2.4.4 py37h622575a_1  # [osx and py==37]
    - gdal  2.4.4 py38h57202bd_1  # [osx and py==38]
    - gdal  2.4.4 py36hbb8311d_1  # [linux and py==36]
    - gdal  2.4.4 py37hf8c3989_1  # [linux and py==37]
    - gdal  2.4.4 py38hfe926b7_1  # [linux and py==38]

  run:
    - python
    - gdal  2.4.4 py36h02fde04_1  # [osx and py==36]
    - gdal  2.4.4 py37h622575a_1  # [osx and py==37]
    - gdal  2.4.4 py38h57202bd_1  # [osx and py==38]
    - gdal  2.4.4 py36hbb8311d_1  # [linux and py==36]
    - gdal  2.4.4 py37hf8c3989_1  # [linux and py==37]
    - gdal  2.4.4 py38hfe926b7_1  # [linux and py==38]
(我从 gdal package listing on the conda-forge channel 复制了那些。)
顺便说一句,既然你提到对你来说真正重要的区别是 libtiff ,那么你应该固定 libtiff 而不是 gdal 吗?或者两者都有?

编辑:
最好避免在 hostrun 部分重复整个构建字符串列表。
正如您在评论中所建议的,一种选择是在 conda_build_config.yaml 中定义构建字符串:
# conda_build_config.yaml
gdal_build:
  - py36h02fde04_1  # [osx and py==36]
  - py37h622575a_1  # [osx and py==37]
  - py38h57202bd_1  # [osx and py==38]
  - py36hbb8311d_1  # [linux and py==36]
  - py37hf8c3989_1  # [linux and py==37]
  - py38hfe926b7_1  # [linux and py==38]
# meta.yaml
requirements:
  build:
    - python
    - 
  host:
    - python
    - pip
    - numpy
    - gdal  2.4.4 {{ gdal_build }}

  run:
    - python
    - gdal  2.4.4 {{ gdal_build }}
另一种选择是直接在 meta.yaml 中定义一个 jinja 变量中的查找表。这可能有点难看,但至少所有的逻辑都包含在一个文件中。我不确定更喜欢哪个。
{% set platform = 'linux' if linux else 'osx' if osx else 'win' %}

{%
  set gdal_builds = {
    'osx': {
      36: 'py36h02fde04_1',
      37: 'py37h622575a_1',
      38: 'py38h57202bd_1',
    },
    'linux': {
      36: 'py36hbb8311d_1',
      37: 'py37hf8c3989_1',
      38: 'py38hfe926b7_1',
    }
  }
%}

requirements:
  build:
    - python
    - 
  host:
    - python
    - pip
    - numpy
    - gdal  2.4.4 {{ gdal_builds[platform][py] }}

  run:
    - python
    - gdal  2.4.4 {{ gdal_builds[platform][py] }}

关于Python 封装 : Creating a dependency on a `conda-forge` package in `conda` `meta.yaml` file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63182614/

相关文章:

python - 如何创建一个列来跟踪另一列中的值在 pandas 中的该行之前出现的次数

python - 如何设置要在 python 脚本中使用的 conda 环境

python-2.7 - 为 Python 2.7、Windows 7 安装 GDAL 2.1 64 位

python - DLL 加载失败 : Unable to use GDAL on windows

python - ComputeBandStats 是否考虑了无数据?

python - 按列名和多索引向多索引数据框添加值

python - 如何使用 glob.glob 模块搜索子文件夹?

Python - 无模式 Apache Avro 数据序列化

python - Conda 删除所有环境(root 除外)

python - 由于缺少 TensorBoard 安装,Spyder Anaconda 从 Keras Libraries CNN : WARNING:root:Limited tf. compat.v2.summary API 中出现错误