Search code examples
pythondockerprefect

ModuleNotFoundError with one Prefect flow, but not the other


Cross-posting this question: https://github.com/PrefectHQ/prefect/discussions/6868

I have a minimal project using Prefect v1.3.1, which you can find here: https://github.com/b-long/aid . I'm having a little difficulty getting the deployment right, after migrating from native code to dockerized code. I am using the latest version of Prefect v1 and need to solve this before I'm able to migrate to Prefect 2.x

I'm using Poetry, but I'm pretty sure there's a pattern here that would apply to Hatch, Pipenv, Flit or other tooling. The problem is observed in registration which logs this toward the end:

ModuleNotFoundError: No module named 'aid'

The command '/bin/sh -c python /opt/prefect/healthcheck.py '["/opt/prefect/flows/basic-pandas-flow.prefect"]' '(3, 10)'' returned a non-zero code: 1
Traceback (most recent call last):
...
ValueError: Your docker image failed to build!  Your flow might have failed one of its deployment health checks - please ensure that all necessary files and dependencies have been included.

If you're a Prefect Guru, I'm guessing you'll be able to solve this issue by reading the log file (see discussion linked above) and looking at my Dockerfile: https://github.com/b-long/aid/blob/main/Dockerfile.prefect


Solution

  • It looks like your package aid is relative to / root file system

    COPY README.md aid/ /aid/
    

    I believe it will work if you make it relative to /aid dir (your working dir is /aid and so init file need to be in /aid/aid/__init__.py)

    COPY README.md /aid/
    COPY aid/ /aid/aid