FileNotFoundError: [Errno 2] No such file or directory: prefect.exceptions.ScriptError: Script a

from prefect.deployments import Deployment
from src.flows import test_flow

    my_deployment = Deployment.build_from_flow(

I am on windows machine. When I run python , it posts the deployment at server, I am using local postgres as server database. So far so good. As soon as I run the flow from UI, I get following error.

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\USER\\AppData\\Local\\Temp\\tmp8dz374otprefect\\containers\\prefect-agent\\src\\flows\\'
prefect.exceptions.ScriptError: Script at 'containers\\prefect-agent\\src\\flows\\'
My src\ and folder are in same directory.


when I debug I see following value under my deployment

my_deployment.entrypoint = src/flow/
my_deployment.path = path/of/project_dir

Not sure why it is trying to locate the file C:\\Users\\USER\\AppData\\Local\\Temp\\tmp8dz374otprefect instead of getting from path variable set in deployment
Please help!!

Have you set up an environment variable for Prefect Home? I’ve encountered errors in the past (self-hosted on Windows) revolving around entry points until I dictated the path where Prefect considers its home (and stores the DB).

@jbmclry Thanks for the reply. I figured out the issue. We have all our deployment in file, It appears Prefect expect to post these deployment from same directory where this file is located…so it can build correct path and entrypoint. I have changed my code to generate always path and entrypoint with respect to where all flows have been imported as module and flow function. This way I do not need to ensure that I am in same directory where file is there and I can run command python /some/path/ instead doing cd to directory .

from src.flows import flow_module
from pathlib import Path

def get_path_and_entrypoint(module, function):
     path = str(Path(__file__).parent.resolve())
    entrypoint = "{}:{}".format(
        str(Path(module.__file__).absolute().relative_to(path)), function.fn.__name__
    return {"path": path, "entrypoint": entrypoint}

print(get_path_and_entrypoint(flow_module, flow_module.flow_function))

# Output
# {"path": "<path/to/>", "entrypoint": "src/flows/flow_module:flow_function_name"}

1 Like

@maheshmmmec Thanks for sharing your solution.