Closed pietermarsman closed 2 years ago
Hey @pietermarsman, do you have a __init__.py
file under those directories where your python files are located?
Yes I have. Changed the description of the issue to reflect this. Sorry, tried to make it as minimal as possible.
Can confirm that I'm having the same behavior. I also have __init__.py
files all around. It works however when I don't do relative imports (or run the pack.py script as python -m pack
but just python pack.py
)
I have the same issue and I'm using absolute, not relative imports. What's the workaround?
@lminer absolute path should work as expected, could you start a separate issue and share more details on how to reproduce it?
I fixed it by appending the root directory to my python path in the module where I create the service and pack the model.
import sys
from os import path
ROOT_DIR = path.dirname(path.dirname(path.abspath(__file__)))
sys.path.append(ROOT_DIR)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
In BentoML, local python modules can be included by specifying the include
filed in the bentofile.yaml
build file. E.g.:
# bentofile.yaml
service: "iris_classifier:svc"
description: "file: ./readme.md"
labels:
foo: bar
team: abc
include:
- "*.py"
- "*.json"
exclude:
- "*.pyc"
Note that BentoML 1.0 no longer try to automatically capture local python dependencies, instead it asks users to specifically include the python files required for their ML service. This design also ensures an identical import path in serving environment, allowing relative imports to work the same way they are in a development environment.
Thanks!
Describe the bug
Local python modules should be copied to the packed bento docker (the thing in ~/bentoml/repository, not sure how to call it). But relative imports are not recognized properly as local python dependencies.
To Reproduce
Have a package structure like this:
and import something from the util.py:
The util.py file is not copied to the bento docker.
Expected behavior
The number of bento docker files should be exactly the same when using relative and absolute imports.
Screenshots/Logs
Output logs of saving the
BentoService
with relative imports:Output log of saving the
BentoService
with absolute imports:Environment:
Additional context
I have a custom
BentoModelArtifact
in _bentoartifact.py that is also not copied properly.