Mitchell Bregman
10/22/2020, 7:54 PM# $ROOT/src/flow.py
from prefect import Flow
flow = Flow(name="test flow")
Now from the command line in dir $ROOT
, I run:
prefect register flow --file src/flow.py --name "test flow"
I get the error
KeyError: "'__name__' not in globals"
What am I doing wrong? I’d like to use the CLI as it will be more simplistic from a CI/CD standpointDylan
Dylan
Dylan
Mitchell Bregman
10/22/2020, 8:45 PM-
?Dylan
Mitchell Bregman
10/22/2020, 8:45 PMZanie
Mitchell Bregman
10/22/2020, 8:47 PMTraceback (most recent call last):
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/bin/prefect", line 8, in <module>
sys.exit(cli())
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/prefect/cli/register.py", line 86, in flow
flow = extract_flow_from_file(file_path=file_path, flow_name=name)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/prefect/utilities/storage.py", line 76, in extract_flow_from_file
exec(contents, exec_vals)
File "<string>", line 18, in <module>
KeyError: "'__name__' not in globals"
Mitchell Bregman
10/22/2020, 8:47 PMZanie
flow.py
file with us? Sometimes this happens when you do relative imports within a script.Mitchell Bregman
10/22/2020, 8:59 PMflow.py
.. just to preface, i set up a cookiecutter
project for my team so that we can have the similar CI/deployment recipe, etc. this is based on that cookiecutter. ill push to GH so you can see the resulting project, 1 secMitchell Bregman
10/22/2020, 9:03 PMMitchell Bregman
10/22/2020, 9:04 PMZanie
__init__.py
you do a relative import from .flow
- https://github.com/mitchbregs/cookiecutter-prefect/blob/master/%7B%7Bcookiecutter.service_name%7D%7D/src/__init__.py#L2Zanie
from src.flow import MyFlow
Zanie
MyFlow = flow
to your flow.py
file and did pip install -e .
and things seem to have workedMitchell Bregman
10/22/2020, 9:43 PMMitchell Bregman
10/22/2020, 9:43 PMMitchell Bregman
10/22/2020, 10:02 PMMyFlow = flow
where did you add that? and whats the reasoning?Zanie
from .flow import MyFlow
but in flow.py
the name of the flow is just flow
not MyFlow
Zanie
Mitchell Bregman
10/22/2020, 10:05 PMMitchell Bregman
10/22/2020, 10:06 PMMitchell Bregman
10/22/2020, 10:07 PMprefect register
i get the following tracebackMitchell Bregman
10/22/2020, 10:07 PMTraceback (most recent call last):
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/bin/prefect", line 8, in <module>
sys.exit(cli())
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/prefect/cli/register.py", line 86, in flow
flow = extract_flow_from_file(file_path=file_path, flow_name=name)
File "/Users/mitchell.bregman/git/pmflows_oj0hxdhv-my_first_flow/venv/lib/python3.8/site-packages/prefect/utilities/storage.py", line 76, in extract_flow_from_file
exec(contents, exec_vals)
File "<string>", line 18, in <module>
ModuleNotFoundError: No module named 'src'
Mitchell Bregman
10/22/2020, 10:07 PM__name__
not in globals argMitchell Bregman
10/22/2020, 10:07 PMMitchell Bregman
10/22/2020, 10:09 PMfrom . import config
from .tasks.task import MyTask
Mitchell Bregman
10/22/2020, 10:09 PM__name__
errorMitchell Bregman
10/22/2020, 10:09 PM__init__
tooZanie
ModuleNotFoundError: No module named 'src'
means you have not installed your module which you would do with pip install -e .
from the top-level where your setup.py isMitchell Bregman
10/22/2020, 10:14 PMMitchell Bregman
10/22/2020, 10:14 PMMitchell Bregman
10/22/2020, 10:14 PMMitchell Bregman
10/22/2020, 10:14 PMZanie
name
error because of how python imports work — we are executing your code without it knowing what file its inZanie
Zanie
Zanie
Mitchell Bregman
10/22/2020, 10:15 PMMitchell Bregman
10/22/2020, 10:15 PMMitchell Bregman
10/22/2020, 10:16 PMZanie