hi, i am experimenting with samples files with pre...
# prefect-community
t
hi, i am experimenting with samples files with prefect, i have to questions, how to solve "*No module named \'lib\'"),* happens when the agent start executing the task
a
can you move the code blocks to the thread?
Regarding your issue, this thread will walk you through various ways how you can solve it
t
i am starting local agent from docker-compose:
Copy code
version: "3.7"
services:
    agent:
        build: .
        command: bash -c "prefect agent local start --name $$(uuid) --no-hostname-label --label development"
        volumes:
            - /srv/docker/prefect/flows:/root/.prefect/flows
            - type: bind
              source: ./config.toml
              target: /root/.prefect/config.toml
              read_only: true
and my client
Copy code
import json
import requests
import prefect
from prefect import Flow, task, Client
from prefect.storage import Local

logger = prefect.context.get("logger")
from prefect.run_configs import LocalRun
from prefect import task, Flow
from prefect.schedules import Schedule
from prefect.schedules.clocks import CronClock
from lib.afunction import get_other_text

import datetime
import pytz

every_10min = "*/1 * * * *"
REF_TZ_BERLIN = 'Europe/Berlin'

schedule = Schedule(clocks=[CronClock(every_10min,start_date=datetime.datetime.now(pytz.timezone(REF_TZ_BERLIN)))])

@task
def get_text():
    return "text"

@task
def put_text(text):
    <http://logger.info|logger.info>("Getting text of {}".format(text))
    print(text + "text")
    return text + "text" + get_other_text()



with Flow("local_test_flow", storage=Local(add_default_labels=False)) as flow:
    text = get_text()
    put_text(text)

try:
    client = Client()
    client.create_project(project_name="weather")
except prefect.utilities.exceptions.ClientError as e:
    <http://logger.info|logger.info>("Project already exists")

#flow.register(project_name="weather", labels=["development"], add_default_labels=False)
FLOW_NAME = "scheduled_local_flow"
with Flow(
    FLOW_NAME,
    storage=Local(add_default_labels=False
                  ),
    schedule=schedule,
    run_config=LocalRun(),
) as flow_schedule:
    text = get_text()
    put_text(text)

flow_schedule.register(project_name="weather", labels=["development"], add_default_labels=False)
docker-compose of the client weather.py:
Copy code
version: "3.7"
services:
    weather:
        build: .
        command: python3 /usr/app/weather.py
        volumes:
            - /srv/docker/prefect/flows:/root/.prefect/flows
            - type: bind
              source: ./weather.py
              target: /usr/app/weather.py
              read_only: true
            - type: bind
              source: ./lib/afunction.py
              target: /usr/app/lib/afunction.py
              read_only: true
            - type: bind
              source: ./config.toml
              target: /root/.prefect/config.toml
              read_only: true
and what's the purpose of this mount??
Copy code
/srv/docker/prefect/flows:/root/.prefect/flows
the import problem only occur if i import a function from other file, but if i used the task/function locally. the flow will execute the task successfully..
🙏 1
a
specifically this one may help you
Copy code
prefect agent local start -p /path/to/your/lib
t
bevor using the import lib function, i was having the same problem, but then this was solved, by adding:
Copy code
/srv/docker/prefect/flows:/root/.prefect/flows
i saw it from sample file, what is this actually doing?? but after the import lib its again the same problem, but thanks i will look to your artikel..
a
Since you want to run things in Docker, you may actually package your dependencies directly into your image - check this example repository, especially this Dockerfile Viel Erfolg! 🇩🇪
👍 1