Hey all, first of all; I'm in love with BentoML! ...
# ask-for-help
d
Hey all, first of all; I'm in love with BentoML! I just ran into the following challenge: I need to preinstall the punkt_tab nltk package in order for my bento to work. I do so in my setup.py script as described in the documentation: setup.py
Copy code
#!/usr/bin/env python
import nltk

print("Downloading NLTK data..")
nltk.download("punkt_tab")
pyproject.toml
Copy code
[tool.bentoml.build.python]
packages = ["nltk"]

[tool.bentoml.build.docker]
setup_script = "./setup.py"
Building the bento works, but when I then try containerizing with bentoml containerize mybento:id --opt platform=linux/amd64 I get the following error as nltk cannot be found. I am on bentoml version 1.4.6 => ERROR [base-container 13/15] RUN chmod +x ./env/docker/script__2721a2a460e1713162fe15a0bf0a1043 && ./env/docker/script__2721a2a460e1713162fe15a0bf0a1043 0.2s ------ > [base-container 13/15] RUN chmod +x ./env/docker/script__2721a2a460e1713162fe15a0bf0a1043 && ./env/docker/script__2721a2a460e1713162fe15a0bf0a1043: 0.204 Traceback (most recent call last): 0.204 File "/home/bentoml/bento/./env/docker/script__2721a2a460e1713162fe15a0bf0a1043", line 3, in module 0.205 import nltk 0.205 ModuleNotFoundError: No module named 'nltk' ------ Dockerfile:45 -------------------- 43 | RUN --mount=type=cache,target=/root/.cache/ uv pip install -r ./env/python/requirements.txt 44 | 45 | >>> RUN chmod +x ./env/docker/script__2721a2a460e1713162fe15a0bf0a1043 && ./env/docker/script__2721a2a460e1713162fe15a0bf0a1043 46 | 47 | COPY --chown=bentoml:bentoml . ./ --------------------
j
Hello, would it be better to perform the download in the constructor of the service?
Copy code
class MyService:
    def __init__(self):
          nltk.download("punkt_tab")
d
Thanks a lot, this helped!