[英]Error to create a flow in prefect for python using with and object Flow()
Hi everyone I was trying to create a flow using prefect for python but I get the error TypeError: 'fn' must be callable , I already install all the packages and I have tried in different IDE like vs code and colab but the result is the same.大家好,我正在尝试使用 python 的 prefect 创建一个流程,但我收到错误TypeError: 'fn' must be callable ,我已经安装了所有的包,我已经尝试过不同的 IDE 像 vs code 和 colab 但结果是相同的。
the code is:代码是:
from prefect import task, Flow
@task()
def load():
print("Loading data")
with Flow("Hello-world") as flow:
load()
flow.run()
#ERROR
TypeError: 'fn' must be callable
I tried changing the code to this but I get a different error:我尝试将代码更改为此,但我得到一个不同的错误:
from prefect import task, Flow
@task()
def load():
print("Loading data")
with Flow(name = "Hello-world") as flow:
load()
flow.run()
#ERROR
TypeError: Flow.__init__() missing 1 required positional argument: 'fn'
I believe you are trying to run a Prefect 1.0 flow using the Prefect 2.0 package.我相信您正在尝试使用 Prefect 2.0 package 运行 Prefect 1.0 流程。
I was able to run your example fine using prefect==1.2.4
and I was able to reproduce your error using prefect==2.0.0
我能够使用
prefect==1.2.4
很好地运行您的示例,并且能够使用prefect==2.0.0
重现您的错误
Here's what your example could look like using prefect>=2.0.0
:这是您的示例使用
prefect>=2.0.0
的样子:
from prefect import flow, task
@task
def load():
print("Loading data")
@flow(name="Hello-world")
def my_flow():
load()
if __name__ == "__main__":
my_flow()
Here are some docs on running prefect 2.0 flows以下是一些关于运行 prefect 2.0 流程的文档
In Prefect 2.0 or major, we need to create a flow how in the next example:在 Prefect 2.0 或major 中,我们需要在下一个示例中创建一个流程:
import pandas as pd
import numpy as np
from prefect import flow, task, Flow
@task
def extract():
pass
@task
def transform():
pass
@task
def load():
pass
"""
with Flow("ETL Test") as flow:
extract()
transform()
load()
flow.run()
"""
@flow
def flow_caso():
extract()
transform()
load()
flow_caso()
In the comments you can see how we can create a flow in Prefect with version minor to 2.0.0, but in versions major you need to create a function with the decorator @flow.在评论中,您可以看到我们如何在 Prefect 中创建版本次要为 2.0.0 的流,但在主要版本中,您需要使用装饰器 @flow 创建 function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.