当 运行 来自 UI 时完善 ModuleNotFoundError

Prefect ModuleNotFoundError when running from UI

我正在学习 Prefect 教程,网址为:https://docs.prefect.io/core/tutorial/01-etl-before-prefect.html。 代码可以从git下载:https://github.com/PrefectHQ/prefect/tree/master/examples/tutorial

教程依赖于 aircraftlib,它是教程下的一个目录。我可以通过终端执行流程:

python 02_etl_...

而且执行得非常完美!

我创建了一个项目,并将 Flow 添加到该项目。通过 Prefect 服务器 UI 我可以 运行 Flow,但失败并显示错误消息:

State Message: Failed to load and execute Flow's environment: ModuleNotFoundError("No module named 'aircraftlib'")

通过Prefect Server执行Flows时如何处理依赖关系UI?

这部分取决于您使用的 Flow Storage 和 Agent 的类型。由于你是 运行 Prefect Server,我假设你使用的是 Local Storage + Local Agent;在这种情况下,您需要确保 aircraftlib 目录位于本地可导入的 Python PATH 中。有几种方法可以做到这一点:

  • 运行你的Prefect Agent在tutorial目录下;然后,您的本地代理的路径将由它提交的流继承
  • 手动将 tutorial/ 目录添加到全局 python 路径(我不推荐这样做)
  • 使用 -p CLI 标志将 tutorial/ 目录添加到您的代理路径;例如:prefect agent start -p ~/Developer/prefect/examples/tutorial(这是我推荐的方法)