Pierre Monico
08/18/2021, 1:31 PMprefect run CLI --module option?
• Doing python -m flows.myflow works
• Doing prefect run -m flows.myflow raises No module named 'flows'Kevin Kho
flows installed as a Python module with pip?Pierre Monico
08/18/2021, 1:40 PM__init__.py) inside the repoPierre Monico
08/18/2021, 1:40 PMKevin Kho
pip install -e . so that it can be imported from whatever directory you’re in. Are you familiar with how to create the setup.py?Zanie
import importlib
from typing import Any
def import_object(name: str) -> Any:
"""Import an object given a fully-qualified name.
Args:
- name (string): The fully-qualified name of the object to import.
Returns:
- obj: The object that was imported.
Example:
```python
>>> obj = import_object("random.randint")
>>> import random
>>> obj == random.randint
True
"""
# Try importing it first so we support "module" or "module.sub_module"
try:
module = importlib.import_module(name)
return module
except ImportError:
# If no subitem was included raise the import error
if "." not in name:
raise
# Otherwise, we'll try to load it as an attribute of a module
mod_name, attr_name = name.rsplit(".", 1)
module = importlib.import_module(mod_name)
return getattr(module, attr_name)```Zanie
PYTHONPATH even if they have not been installed with pipPierre Monico
08/18/2021, 2:43 PMPierre Monico
08/18/2021, 2:45 PMpython -m as a matter of fact.Pierre Monico
08/18/2021, 2:46 PMZanie
Pierre Monico
08/18/2021, 2:49 PMpython -m and prefect run -m ) and executed the function with the same argument and guess what: it works.Zanie
import mod importlib.import_module("mod") and python -m mod with a simple folder and it worked.Zanie
Pierre Monico
08/18/2021, 2:50 PMpipenv and running this inside a virtual environment.Pierre Monico
08/18/2021, 3:03 PM