Yao Hu
10/09/2025, 3:45 PMfrom 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",
)Marvin
10/09/2025, 3:45 PMMarvin
10/09/2025, 3:47 PMfrom_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:
from pathlib import Path
print(Path(__file__).parent)
print(Path(__file__).parent.exists())
- Also share the output of:
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:
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.Yao Hu
10/09/2025, 3:59 PMexists() 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/LinuxYao Hu
10/09/2025, 4:00 PMexists() 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/LinuxMarvin
10/09/2025, 4:00 PMMarvin
10/09/2025, 4:03 PMpython -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`:
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:
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.