Oussama Louati
04/09/2021, 2:16 PMdocker run my_image
, i get this error each time:
Failed to load and execute Flow's environment: ModuleNotFoundError("No module named '/root/'")
Should i run the agent inside the container ? Thank youKevin Kho
Oussama Louati
04/09/2021, 4:27 PMKevin Kho
Oussama Louati
04/09/2021, 4:57 PM|-- code/
| |-- README.md
| |-- code/
| |-- code/
|-- code/
|-- workflow/
| |-- flow.py/
|-- environment.yml
|-- Dockerfile
|-- requirements.txt
• This is a valid workflow that can be ran using workflow/flow.py
• So next step i build the image from that Dockerfile: docker build -t test:latest .
FROM prefecthq/prefect:0.14.14-python3.7
... Run some steps and installations etc etc...
ADD . .
SHELL ["/bin/bash", "-c"]
CMD ["python", "/webbeds/workflow/flow.py"]
• in my flow.py i have something like this :
flow = Flow("Flow name")
flow.executor = LocalDaskExecutor(scheduler="threads")
id=flow.register(project_name="project_name")
Client=Client()
Client.create_flow_run(flow_id=id, run_config=DockerRun(), run_name="run_name", labels=["agent_name"])
• I even tried to pass DockerRun(image="test:latest")
• Then I ran : prefect agent docker start --show-flow-logs -l agent-name --no-pull
• Then i ran my image: docker run test:latest
• The agent picks up the flow as shown in the screenshot below.
• On the web ui i just get the error:
Failed to load and execute Flow's environment: ModuleNotFoundError("No module named '/root/'")
Kevin Kho
create_flow_run
in the flow.py? Are you trying to run immediately?Oussama Louati
04/09/2021, 5:08 PMKevin Kho
Kevin Kho
flow.py
like:
@task
def test_task():
return "hello"
with Flow("test_flow") as flow:
test_task()
flow.register("project_name")
Kevin Kho
Oussama Louati
04/09/2021, 5:13 PMKevin Kho
python flow.py
right?Oussama Louati
04/09/2021, 5:14 PMKevin Kho
Kevin Kho
Oussama Louati
04/09/2021, 5:17 PMKevin Kho
prefect backend server
right?Oussama Louati
04/09/2021, 5:18 PMKevin Kho
prefect agent local start
Oussama Louati
04/09/2021, 5:42 PMKevin Kho
flow.py
we had? I think this is because the Flows are picked up by Agents with the same labels. Let’s try putting labels on both the Flow and the Agent so the Agent will know it can pick up that flow.Oussama Louati
04/09/2021, 5:45 PMOussama Louati
04/09/2021, 5:46 PMKevin Kho
LocalAgent
and it picked up when you hit the “Run Now”?Oussama Louati
04/09/2021, 5:47 PMKevin Kho
Flow()
with Flow(run_config = DockerRun(whatever))
Oussama Louati
04/09/2021, 5:50 PMKevin Kho
prefect agent docker start
and other stuff you need like this: https://docs.prefect.io/orchestration/agents/docker.html#agent-configurationKevin Kho
Kevin Kho
Oussama Louati
04/09/2021, 5:55 PMFailed to load and execute Flow's environment: ModuleNotFoundError("No module named '/home/oussamalouati/'")
Kevin Kho
Kevin Kho
Oussama Louati
04/09/2021, 5:58 PMOussama Louati
04/09/2021, 5:58 PMOussama Louati
04/09/2021, 5:59 PMKevin Kho
Kevin Kho
Oussama Louati
04/09/2021, 6:14 PMOussama Louati
04/09/2021, 6:16 PMFROM prefecthq/prefect:0.14.14-python3.7
ENV PYTHONPATH /app:$PYTHONPATH
RUN apt-get update --fix-missing && \
apt-get install -y wget bzip2 ca-certificates curl git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
ENV CONDA_DIR $HOME/miniconda3
RUN wget --quiet <https://repo.anaconda.com/miniconda/Miniconda3-py38_4.8.3-Linux-x86_64.sh> -O ~/miniconda.sh && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p $CONDA_DIR && \
rm ~/miniconda.sh
ENV PATH ${CONDA_DIR}/bin:$PATH
ADD environment.yml .
RUN conda env create -f environment.yml && \
rm -rf $CONDA_DIR/pkgs/* && \
conda init && \
echo "conda activate myEnv" >> /root/.bashrc
ENV PATH ${CONDA_DIR}/envs/melqart/bin:$PATH
ADD . .
SHELL ["/bin/bash", "-c"]
CMD ["python", "/app/workflow/flow.py"]
Kevin Kho
Oussama Louati
04/09/2021, 6:24 PM|-- components/
| |-- README.md
| |-- code/
| |-- code/
|-- code/
|-- workflow/
| |-- flow.py/
|-- environment.yml
|-- Dockerfile
|-- requirements.txt
And in my imports, i have imports like : from *components*.whatever import whatever
Because i am adding /app
to the $PYTHONPATH in the dockerfileOussama Louati
04/09/2021, 6:24 PMKevin Kho
Kevin Kho
RunConfig
and default Storage
that are both Local. LocalRun
and LocalStorage
. What happens when you register a flow with these is that Prefect saves a serialized form in Users/username
, the default LocalStorage location. When Prefect runs a flow, it looks for this serialized version and unpickles it and runs it.Kevin Kho
LocalStorage
with DockerRun
. The LocalStorage default is Users/username
so Prefect starts looking for that location in the Docker container and trying to find the serialized script to run. This is the error.Kevin Kho
Kevin Kho
Flow("name", storage=Local(path="/app/workflow/flow.py", stored_as_script=True)
. The stored as script is to specify to not pickle it.Kevin Kho
Kevin Kho
Oussama Louati
04/09/2021, 8:41 PMFailed to load and execute Flow's environment: ModuleNotFoundError("No module named '/app/workflow/flow'")
Kevin Kho
Kevin Kho
Kevin Kho
path="/app/workflow/"
. I think it has to be a directory.Oussama Louati
04/09/2021, 9:00 PMflow = Flow("flow name", run_config=DockerRun(), storage=Local(path="/app/workflow/flow.py", stored_as_script=True))
Oussama Louati
04/09/2021, 9:01 PMpath="/app/workflow/"
, same errorKevin Kho
Kevin Kho
Oussama Louati
04/09/2021, 9:02 PMKevin Kho
Kevin Kho
Oussama Louati
04/11/2021, 9:51 PMFailed to load and execute Flow's environment: FileNotFoundError(2, 'No such file or directory')
😕Kevin Kho
Kevin Kho
Kevin Kho
Oussama Louati
04/11/2021, 10:00 PMprefecthq/prefect:0.14.14-python3.7
Kevin Kho
Oussama Louati
04/11/2021, 10:04 PMKevin Kho
Oussama Louati
04/11/2021, 10:07 PMKevin Kho
Kevin Kho
Oussama Louati
04/11/2021, 10:10 PMpip install -e .
to install my components). Yes, we see about it tomorrow.Kevin Kho
Oussama Louati
04/11/2021, 10:20 PMKevin Kho
Kevin Kho
Kevin Kho
RUN pip install -e .
is after the ADD . .
right?Kevin Kho
Oussama Louati
04/13/2021, 10:10 AMKevin Kho
Oussama Louati
04/13/2021, 2:50 PMKevin Kho
Kevin Kho
flow.run(with_backend="cloud")
, but in the mean time, the best way to run a flow instantly is using the GraphQL API. There is a create_flow_run
mutation and you can use.Kevin Kho
Kevin Kho
create_flow_run
Oussama Louati
04/15/2021, 12:50 PMflow = Flow(FLOW_NAME,storage=Local(path="/app/workflowflow.py",stored_as_script=True), run_config=DockerRun(image=IMAGE_NAME, labels=[AGENT_NAME]))
.... .....
.... .....
flow.executor = LocalDaskExecutor(scheduler=EXECUTOR_SCHEDULER)
id= flow.register(project_name= PROJECT_NAME)
Client=Client()
Client.create_flow_run(flow_id=id, run_name= RUN_NAME, labels=[AGENT_NAME])
When run it gives me : Failed to load and execute Flow's environment: ValueError('One of flow_id or version_group_id must be provided')
Kevin Kho
client=Client()
. Try also printing your id
to see if that was successful.
id = flow.register('tutorial')
from prefect import Client
client=Client()
client.create_flow_run(flow_id=id, run_name="test")