'How can I make a Python package developed with Poetry available on conda-forge (or even on my personal conda channel)?

I have developed my first Python package using Poetry as a dependency management and packaging tool.

Publishing my work to PyPI has been as easy as running:

poetry publish --build

Now, I'd like to make my package available in the conda ecosystem too. As a preliminary step, I've tried to build it locally with conda build.

This is what my (anonymized) meta.yaml file looks like:

{% set version = "0.1.4" %}

package:
  name: "<my-package-name>"
  version: {{ version }}

source:
  url: <URL-of-the-source-distribution-of-my-package-on-PyPI>.tar.gz
  sha256: <SHA256-of-the-source-distribution-of-my-package-on-PyPI>

build:
  noarch: python
  script: python -m pip install .

requirements:
  host:
    - python
    - pip
  run:
    - python

about:
  license: MIT
  license_familY: MIT
  license_file: LICENSE
  summary: "<Brief-project-description>"

Upon running conda build, the following exception is raised:

ModuleNotFoundError: No module named 'poetry'

immediately after these lines:

[...]
Processing $SRC_DIR
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'

This is my very first time creating a conda package.

Please, help me understand what I'm missing and if there is an easier way to make my Poetry project available as a conda package on conda-forge or even on my personal anaconda channel.



Solution 1:[1]

You seem to be missing the build requirements section.

requirements:
  build:
    - python
    - pip
    - poetry

Solution 2:[2]

The following worked for me:

package:
    name: custom-package
    version: "0.1"

source:
    path: ./

build:
  noarch: python
  script: {{PYTHON}} -m pip install .


requirements:
  build:
    - python
    - pip
    - poetry

  host:
    - python
    - poetry

  run:
    - python
    - poetry

Make sure you:

  • use {{PYTHON}} instead of python
  • include poetry in both build and host requirements

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wim
Solution 2 Narek