It is possible to create the tasks in a separate f...
# prefect-server
g
It is possible to create the tasks in a separate file and import everything just to run in one flow? The idea is that something changes, i would be able to see directly on Git which file has changed. I tried to do on my end, but the task didn’t ran.
a
@Guilherme Petris it’s much easier if tasks are defined together with a flow, but importing them is also possible. But to deploy such flow to the backend, you would need to make sure that those tasks can be imported, e.g.: 1. Use Docker storage (with Docker based agents) to ensure task files are copied to the storage 2. Provide a path when using a Local agent 3. or build a package containing those tasks as module and install in the execution env
g
Interesting - i’m trying to run locally and i’m getting the ModuleNotFoundError: No module name “x” even though that i already added
__init__.py
inside the folder and apparently i can’t import the tasks separately. Have to put everything in the same folder basically.
a
Gotcha. I think with local agent this should be quite straightforward, because you can simply add a path to your modules in the LocalRun:
Copy code
from prefect.run_configs import LocalRun

with Flow("yourflow", run_config=LocalRun(working_dir="/path/to/your/modules")) as flow:
or add it when starting the agent:
Copy code
prefect agent local start -p /Users/you/your_modules
g
Well, it still doesn’t work - My folder structure: Pendo (ROOT) ----flows --------prefect_flow ----pendo_tasks --------task1 When i try to import from pendo_task i get the moduleerror saying that There is no module called pendo_tasks (it’s just a folder, even thhough that i try to do
from pendo_task import task1
a
can you zip and share your project? I would try to reproduce. Just redact anything sensitive
alternatively, you could commit to Github and share a link
d
@Anna Geller Hi, was this resolved, I am also facing similar issue. Any resolution here? While running flows, I am getting
ModuleNotFoundError
for imported modules from the same project directory. How to handle such imports?
Copy code
project
|_lib
   |_ util.py
   |_ common.py
|_flows
   |_ flow1.py // imports util etc here which is throwing error
   |_ flow2.py
I have added path to the lib directory to the LocalRun working_dir config, but it still throws the same error.