Lesson 2: how to ensure fast.io is installed in huggingface?

I’m trying to follow Lesson 2, deploying the application and the model to huggingface. I’ve committed and pushed my changes and huggingface is giving me the following error:

Traceback (most recent call last):
File “app.py”, line 1, in
from fastai.vision.all import *
ModuleNotFoundError: No module named ‘fastai’

How do I install the required python modules in huggingface?

Hey Thomas, :wave:

You need to tell huggingface what requirements your code needs to run.

You do this by providing a requirements.txt file in the root of your project directory. The following links will give you a little more information about how to structure a python project which you may find helpful.

If you’re on google colab you can generate a requirements.txt file by typing the following in colab terminal (icon bottom left of the window), after running all the cells in your notebook.

pip freeze > requirements.txt

You can then add the requirements.txt to your project directory and push that to huggingface.

I hope this moves you forward. Please let me know if you have any questions/issues. :slightly_smiling_face:

1 Like

Thanks, that worked and I was able to deploy my app to hugging faces. Just wondering though, pip freeze produced a file with over 200 lines in it, presumably including all the python modules in my OS installation. Wondering if there is a way to generate requirements.txt containing only the modules my python script is actually using.

I’m glad I was able to help you! :slightly_smiling_face:

If you’re using pip locally you should look at using a virtual environment. This will give you a way of installing specific packages and their versions for a given project you’re working on so you can avoid conflicting versions, etc.

Here’s a pretty comprehensive overview of what a virtual environment is.

Here’s a guide to set up a virtual environment on your machine using virtualenv

There are a number of different ways to create and manage virtual environments. I know Jeremy recommends anaconda/mamba.

Here’s an answer on stack overflow that compares different virtualenv managers.

Edit

I forgot to mention that when you install a package e.g. Gradio you’re also installing the dependencies of that package as well. These are called transitive dependencies. Below is part of the output of running pip install gradio

Installing collected packages: pydub, ffmpy, websockets, uc-micro-py, semantic-version, python-multipart, orjson, multidict, h11, frozenlist, async-timeout, aiofiles, yarl, uvicorn, starlette, mdit-py-plugins, linkify-it-py, huggingface-hub, httpcore, aiosignal, httpx, fastapi, aiohttp, gradio-client, gradio

This is one of the reasons your requirements.txt file is so large even if you use a virtual environment. :slightly_smiling_face:

The Pip Chill library can perhaps do this: pip-chill · PyPI
It only lists packages that are not dependencies of other packages.

Though it still is a good idea to create a virtual environment as @Grey-Shirt said. Though Pip Chill can still be useful in virtual environments.