Preston Sharpe
09/24/2025, 12:21 AMprefect server start
locally and then also serving a basic flow. I'm running into the error No module named prefect.engine
. I'm assuming I have a misconfiguration in my environment. Running prefect --version
yields version 3.4.18Marvin
09/24/2025, 12:21 AMMarvin
09/24/2025, 12:23 AMprefect.engine
module — that was part of older Prefect internals. The error means something (your code or a dependency) is trying to import prefect.engine
, which will fail on 3.4.18.
Common causes and fixes:
- You (or a library) have a 2.x-era import like import prefect.engine
or from prefect.engine...
. Remove or update these — user code in 3.x should not import engine internals.
- Mixing environments (e.g., running prefect server start
with one interpreter and running your flow with another) so the wrong set of packages is being used.
- Old Prefect 2.x “collections” (prefect-aws, prefect-docker, etc.) still installed. In Prefect 3.x these moved into extras; older packages can import old paths.
Quick checks
1) Verify what Prefect you’re importing when your script runs:
python -c "import prefect, sys; print(prefect.__version__, prefect.__file__, sys.executable)"
2) Make sure your flow code doesn’t import engine internals. A minimal working example in 3.x:
from prefect import flow, task, get_run_logger
@task
def say_hi(name: str):
logger = get_run_logger()
<http://logger.info|logger.info>(f"Hi, {name}!")
@flow
def my_flow():
say_hi("world")
if __name__ == "__main__":
my_flow.serve(name="demo") # or my_flow()
3) Check for old packages and upgrade/uninstall as needed:
pip freeze | grep -i prefect
# If you see prefect-aws / prefect-docker / prefect-kubernetes, uninstall them:
pip uninstall -y prefect-aws prefect-docker prefect-kubernetes
# Ensure Prefect 3 is current
pip install -U "prefect>=3.4,<4"
# If you need integrations, install extras (example):
pip install -U "prefect[aws]" "prefect[docker]" "prefect[kubernetes]"
4) Make sure there’s no local shadowing:
- No file/folder named prefect
in your project.
- Run which prefect
(or where prefect
on Windows) and confirm it’s from the same environment you use to run your script.
If the error persists, could you paste the full traceback? That will show exactly which import is trying to load prefect.engine
and we can pinpoint the source.
References:
- Prefect 3.x docs
- Prefect 3 GA announcementPreston Sharpe
09/24/2025, 12:29 AMprefect
so that was probably messing with the import!