How do I import add
in pipeline.py
while using containerized python components?
#11186
Answered
by
stephenleo
stephenleo
asked this question in
Q&A
-
How do I import Here's my directory structure pipeline.py
src/
|--math_utils.py
|--my_component.py Using code exactly from the documentation, runs into this error: $ python -m pipeline
Traceback (most recent call last):
File "/opt/conda/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/opt/conda/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/jupyter/mlops-on-gcp/test/pipeline.py", line 4, in <module>
def addition_pipeline(x: int, y: int) -> int:
File "/opt/conda/lib/python3.10/site-packages/kfp/dsl/pipeline_context.py", line 65, in pipeline
return component_factory.create_graph_component_from_func(
File "/opt/conda/lib/python3.10/site-packages/kfp/dsl/component_factory.py", line 673, in create_graph_component_from_func
return graph_component.GraphComponent(
File "/opt/conda/lib/python3.10/site-packages/kfp/dsl/graph_component.py", line 58, in __init__
pipeline_outputs = pipeline_func(*args_list)
File "/home/jupyter/mlops-on-gcp/test/pipeline.py", line 5, in addition_pipeline
task1 = add(a=x, b=y)
NameError: name 'add' is not defined Updating from kfp import dsl, compiler
from src.my_component import add
@dsl.pipeline
def addition_pipeline(x: int, y: int) -> int:
task1 = add(a=x, b=y)
task2 = add(a=task1.output, b=x)
return task2.output
compiler.Compiler().compile(addition_pipeline, 'pipeline.yaml') runs into this error $ python -m pipeline
Traceback (most recent call last):
File "/opt/conda/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/opt/conda/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/jupyter/mlops-on-gcp/test/pipeline.py", line 2, in <module>
from src.my_component import add
File "/home/jupyter/mlops-on-gcp/test/src/my_component.py", line 2, in <module>
from math_utils import add_numbers
ModuleNotFoundError: No module named 'math_utils' |
Beta Was this translation helpful? Give feedback.
Answered by
stephenleo
Sep 14, 2024
Replies: 1 comment
-
Documentation update to make it work here: kubeflow/website#3873 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
stephenleo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Documentation update to make it work here: kubeflow/website#3873