Hi, I'm using flytekit 1.14 and I'm trying to use ...
# flyte-support
l
Hi, I'm using flytekit 1.14 and I'm trying to use map tasks and dynamic tasks but I keep getting
ModuleNotFoundError: No module named 'site-packages'
This is the complete traceback:
Copy code
/opt/venv/bin/pyflyte-execute:8 in <module>                                  │
│                                                                              │
│ ❱ 8 │   sys.exit(execute_task_cmd())                                         │
│                                                                              │
│ /opt/venv/lib/python3.10/site-packages/click/core.py:1161 in __call__        │
│                                                                              │
│ ❱ 1161 │   │   return self.main(*args, **kwargs)                             │
│                                                                              │
│ /opt/venv/lib/python3.10/site-packages/click/core.py:1082 in main            │
│                                                                              │
│ ❱ 1082 │   │   │   │   │   rv = self.invoke(ctx)                             │
│                                                                              │
│ /opt/venv/lib/python3.10/site-packages/click/core.py:1443 in invoke          │
│                                                                              │
│ ❱ 1443 │   │   │   return ctx.invoke(self.callback, **ctx.params)            │
│                                                                              │
│ /opt/venv/lib/python3.10/site-packages/click/core.py:788 in invoke           │
│                                                                              │
│ ❱  788 │   │   │   │   return __callback(*args, **kwargs)                    │
│                                                                              │
│ /opt/venv/lib/python3.10/site-packages/flytekit/bin/entrypoint.py:715 in     │
│ execute_task_cmd                                                             │
│                                                                              │
│ ❱ 715 │   _execute_task(                                                     │
│                                                                              │
│ /opt/venv/lib/python3.10/site-packages/flytekit/bin/entrypoint.py:579 in     │
│ _execute_task                                                                │
│                                                                              │
│ ❱ 579 │   │   resolver_obj = load_object_from_module(resolver)               │
│                                                                              │
│ /opt/venv/lib/python3.10/site-packages/flytekit/tools/module_loader.py:51 in │
│ load_object_from_module                                                      │
│                                                                              │
│ ❱ 51 │   class_obj_mod = importlib.import_module(".".join(class_obj_mod))    │
│                                                                              │
│ /usr/lib/python3.10/importlib/__init__.py:126 in import_module               │
│                                                                              │
│ ❱ 126 │   return _bootstrap._gcd_import(name[level:], package, level)        │
│ in _gcd_import:1050                                                          │
│ in _find_and_load:1027                                                       │
│ in _find_and_load_unlocked:992                                               │
│ in _call_with_frames_removed:241                                             │
│ in _gcd_import:1050                                                          │
│ in _find_and_load:1027                                                       │
│ in _find_and_load_unlocked:992                                               │
│ in _call_with_frames_removed:241                                             │
│ in _gcd_import:1050                                                          │
│ in _find_and_load:1027                                                       │
│ in _find_and_load_unlocked:992                                               │
│ in _call_with_frames_removed:241                                             │
│ in _gcd_import:1050                                                          │
│ in _find_and_load:1027                                                       │
│ in _find_and_load_unlocked:1004                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
ModuleNotFoundError: No module named 'site-packages'
I tried using @ancient-wolf-19325 and it says to use python project structure which I did but I still keep getting either the same
ModuleNotFoundError
or
Empty module name
a
Reasoning Complete! 🤖 🔍 Searched knowledge base: To help you resolve the 'ModuleNotFoundError: No module named 'site-packages'' issue with flytekit 1.14, I'll look up relevant documentation and known solutions for this error when using map and dynamic tasks. • Searching over 10 data sources from the following: File, Github File, Github Issue, Web • Found 54 documents that could be relevant from the following data sources: Github File, Github Issue, Web Content. • Filtered down to the top 30 most relevant documents. ✍️ Generated answer: I've found clear guidance on why this error happens and how to resolve it, so I'm ready to provide you with a complete answer.
This error (
ModuleNotFoundError: No module named 'site-packages'
) when using map tasks or dynamic tasks in Flytekit is often due to issues with how your Python project/package is structured or how modules are referenced/imported. Specifically, it can occur if your workflow or task files are not part of a proper Python package (i.e., missing
__init__.py
files), or if the import paths are incorrect, causing Flytekit to misinterpret the module location as
site-packages
rather than your project directory. This is a known issue in Flytekit when the project structure or registration process is not set up as expected by Flytekit's module loader logic, especially for dynamic and map tasks which rely on correct module resolution [source 1] [source 2]. To resolve this, ensure: - Your workflow and task files are inside a Python package (a directory with an
__init__.py
file). - You are running
pyflyte run
or registering from the project root, and your import statements use the correct package/module paths. - Avoid naming your scripts or packages with names that could conflict with standard library or installed packages (like
site-packages
). - If you are using
ImageSpec
, ensure the
source_root
is set correctly and your code is included in the image. Would you like a step-by-step guide to structuring your project and troubleshooting this error? Sources: - GitHub Issue: Task fails to import modules in pyflyte-map-execute mode - GitHub Issue: Dynamic workflows: Module from file ... cannot be loaded 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
a
Have you activated your virtual env
Copy code
source .venv/bin/activate
If you are using uv then do a : uv run CODE.PY This error is bcos you are not in the correct env when you are running the code. Look at the error from your trace:
Copy code
/opt/venv/lib/python3.10/site-packages/flytekit/tools/module_loader.py:51 in │
│ load_object_from_module                                                      │
│                                                                              │
│ ❱ 51 │   class_obj_mod = importlib.import_module(".".join(class_obj_mod))    │
│                                                                              │
│ /usr/lib/python3.10/importlib/__init__.py:126 in import_module
They are pointing to different python installation There is also a hacky way todo it as below:
Copy code
export PYTHONPATH="/absolute/path/to/your/module:$PYTHONPATH"
python your_script.py