<@ULVA73B9P> I would like to install my prefect wo...
# ask-marvin
s
@Marvin I would like to install my prefect workflow as a package and be able to run it from anywhere on my machine. When I try to run the workflow from a directory that doesn't contain the workflow as a subdirectory of my current path I get an error. The error comes from prefect.deployments.runner calling pathlib.Path.relative_to between with my current working directory and the path to my workflow. Is there a way around this? Here is the error: File "$HOME/devel/my-flow/.venv/lib/python3.10/site-packages/prefect/deployments/runner.py", line 609, in from_flow Path(flow_file).absolute().relative_to(Path.cwd().absolute()) File "/usr/lib/python3.10/pathlib.py", line 818, in relative_to raise ValueError("{!r} is not in the subpath of {!r}" ValueError: '$HOME/devel/my-flow/src/my_flow/my_flow_flow.py' is not in the subpath of '$HOME/test' OR one path is relative and the other is absolute.
m
It seems you're facing an issue with Prefect when trying to run your workflow from a directory that doesn't contain the workflow as a subdirectory. The error arises from using
pathlib.Path.relative_to
, which expects both paths to be in a parent-child relationship. To work around this issue, you can consider the following approaches: 1. Deployment Configuration: Ensure that your deployment is configured correctly. You can use a
prefect.yaml
file or the
flow.deploy()
method to specify deployment parameters. This might help in setting up your workflow to run from any location. More details can be found in the Prefect documentation. 2. Filesystem Handling: If the issue is related to how filesystems are handled, ensure that any relative paths are correctly resolved before being used. This can be done by converting paths to absolute paths using
Path.absolute()
before invoking
relative_to
. 3. Custom Script: As a workaround, you might create a custom script that changes the working directory to the one containing your workflow before executing it. No specific issues related to this error were found in the Prefect GitHub repository, suggesting it might be a configuration or usage nuance rather than a bug. If these suggestions don't resolve your issue, consider reaching out to the Prefect community or filing an issue with detailed information about your setup.
n
hi @Scott - you may want to check out https://github.com/zzstoatzz/prefect-pack
tldr I don't have flows in my
src/package_name
but you totally can
personally (this is subjective) I like to have my workflows outside of any package I would build and reserve the package for shared utils (like custom deployment steps or python utils) that many flows may be stakeholders of
as for your error, is it possible you have some path issue?
Copy code
my_flow_flow.py
or is this the right filename?
s
I'll take a look at that repo.
Copy code
my_flow_flow
is probably a string replacement error. I replaced all my file names and directories before submitting the question.
👍 1