0

Sometimes, a Python library depends on additional data, such as ML models. This could be a model from transformers, spacy, nltkand so on. Typically there is a command to download such a model:

python -m nltk.downloader stopwords

How can I have this done automatically when my library is installed, when I use modern python packaging (pyproject.toml) and tools (uv)? The reason is that my library is used in another application and that application shouldn't be concerned what models I use under the hood. But I also don't want to download them at run time. AFAIK, there is no post install step anymore.

I could provide a post install command in my package that the user would have to manually execute once. Is there any convention for this?

At least for spacy, the models are distributed as wheels. However, they can't be used as dependencies by uv since they are lacking versions.

asked Feb 20, 2025 at 7:21

1 Answer 1

1

When using modern packaging you can not execute arbitrary code during installation. I suggest you have the package check the availability of the necessary dependencies at entrypoint/import time and inform the user. Based on your error message the user can then call a different entrypoint/function that will install the necessary dependencies. This installation should only run if the missing dependencies are not already found.

answered Feb 20, 2025 at 7:31
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.