<@ULVA73B9P> when I deploy the following workflow ...
# ask-marvin
y
@Marvin when I deploy the following workflow to cloud, it shows the error: [Errno 2] No such file or directory: '/mnt/c/Users/huyao/Documents/github/qcsched/prefect'
Copy code
from pathlib import Path
from prefect import flow

@flow(log_prints=True)
def my_flow(name: str = "world"):
    print(f"Hello {name}! I'm a flow from a Python script!")

if __name__ == "__main__":
    my_flow.from_source(
        source=str(Path(__file__).parent),
        entrypoint="flow_cloud.py:my_flow",
    ).deploy(
        name="my-deployment",
        parameters=dict(name="Marvin"),
        work_pool_name="test",
    )
m
thought for 163.8 seconds
Thanks for sharing the snippet — the error usually means the deploy() step is trying to package your source directory but can’t read the path you passed to
from_source
. What’s happening - In Prefect 3.x,
flow.from_source(...).deploy(...)
packages the directory you give as
source
and uploads it as part of the deployment. If that path isn’t readable from the process running the script, you’ll see “[Errno 2] No such file or directory”. - Your
source=str(Path(__file__).parent)
is resolving to
/mnt/c/Users/huyao/Documents/github/qcsched/prefect
, which is a WSL path. If you’re running the script with Windows Python (outside WSL), that path won’t exist. Conversely, if you’re in WSL but the directory actually isn’t present/mounted as expected, you’ll see the same error. Quick checks - Run this to confirm what
source
resolves to and whether it exists at runtime:
Copy code
from pathlib import Path
print(Path(__file__).parent)
print(Path(__file__).parent.exists())
- Also share the output of:
Copy code
prefect version
uname -a  # if in WSL
Ways to fix 1) Make the path and runtime match - If you’re running the script in WSL, ensure the repo is accessible under that path (consider moving the repo into your WSL home, e.g.
/home/<you>/repo
, to avoid Windows mount nuances). - If you’re running in Windows Python, your
Path(__file__).parent
should resolve to something like `C:\Users\...`; if you’re seeing
/mnt/c/...
, the script is likely running under WSL. 2) Prefer Git-based source (recommended for portability) - This avoids local path issues entirely:
Copy code
from pathlib import Path
from prefect import flow

@flow(log_prints=True)
def my_flow(name: str = "world"):
    print(f"Hello {name}! I'm a flow from a Python script!")

if __name__ == "__main__":
    my_flow.from_source(
        source="<https://github.com/<owner>/<repo>>",
        entrypoint="prefect/flow_cloud.py:my_flow",  # path within the repo
    ).deploy(
        name="my-deployment",
        parameters={"name": "Marvin"},
        work_pool_name="test",
    )
Notes and docs - In Prefect 3.x,
from_source
supports local directories and Git URLs;
deploy()
packages and uploads your flow code so workers can fetch it. See Store your flow code. - General 3.x deployment info: Release notes and Deployment examples. If you can paste: - the exact value printed by
Path(__file__).parent
- whether
exists()
returns True - whether you’re running the script from Windows Python or inside WSL …I can give you a precise next step.
y
the output of Path(file).parent is /mnt/c/Users/huyao/Documents/github/qcsched/prefect,
exists()
returns True, prefect version is 3.4.22, and the output of uname -a is Linux smallcat-pc 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 002155 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
@Marvin the output of Path(file).parent is /mnt/c/Users/huyao/Documents/github/qcsched/prefect,
exists()
returns True, prefect version is 3.4.22, and the output of uname -a is Linux smallcat-pc 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 002155 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
m
thought for 215.2 seconds
Thanks for the details — super helpful. Two likely causes and fixes: 1) Your project folder is named “prefect” - Your script lives under …/qcsched/prefect, which collides with the installed Prefect package name. This can confuse import/resource resolution during packaging and surface as a FileNotFoundError on that directory. - Fix: rename that folder to something else (e.g., qcsched/flows or qcsched/prefect_flows) and update your entrypoint accordingly, then retry. - Quick sanity check:
Copy code
python -c "import prefect, sys; print('prefect package file:', prefect.__file__); print('sys.path[0]:', sys.path[0])"
You want prefect.file to point to site-packages, not your repo. 2) WSL path/mount quirks under /mnt/c - Although
exists()
is True, packaging sometimes stumbles on Windows-mounted paths. Moving the repo into your WSL home usually resolves this: - Move to e.g.
/home/<you>/qcsched
and update
source
to that path (or use
Path(__file__).parent.resolve()
from the new location). - Alternatively, avoid local-path packaging by using a Git URL for `source`:
Copy code
from prefect import flow

@flow(log_prints=True)
def my_flow(name: str = "world"):
    print(f"Hello {name}! I'm a flow from a Python script!")

if __name__ == "__main__":
    my_flow.from_source(
        source="<https://github.com/<owner>/<repo>>",
        entrypoint="path/in/repo/flow_cloud.py:my_flow",
    ).deploy(
        name="my-deployment",
        parameters={"name": "Marvin"},
        work_pool_name="test",
    )
Also try resolving to an absolute path explicitly if you keep local storage:
Copy code
source=str(Path(__file__).parent.resolve())
Docs for context: Store your flow code If the error persists after renaming the folder and/or moving into your WSL home, please paste the full traceback from the deploy call — that will let me pinpoint exactly where it’s failing.