Fix issue #2526: Add utility to resolve ModuleNotFoundError when running flows from custom scripts

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-04-05 22:32:12 +00:00
parent d216edb022
commit 2643f4c69a
5 changed files with 210 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
"""
Example script showing how to run a CrewAI flow from a custom script.
This example demonstrates how to avoid the ModuleNotFoundError when
starting flows from custom scripts outside of the CLI command context.
"""
import os
from crewai.utilities.path_utils import add_project_to_path
add_project_to_path()
from my_flow.main import MyFlow
def main():
"""Run the flow from a custom script."""
flow = MyFlow()
result = flow.kickoff()
print(f"Flow completed with result: {result}")
if __name__ == "__main__":
main()