ModuleNotFoundError: No module named 'transformers'

Hi! I’ve been having trouble getting transformers to work in Spaces.

When tested in my environment using python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('we love you'))", the results show it’s been properly installed. When imported in Colab it works fine too, but whenever deployed to Spaces it always returns the same ModuleNotFound error. Full traceback message:

Traceback:

File "/home/user/.local/lib/python3.8/site-packages/streamlit/script_runner.py", line 354, in _run_script
    exec(code, module.__dict__)File "/home/user/app/app.py", line 1, in <module>
    from transformers import pipeline

It’s a simple test app using transformers and streamlit, - both of which were reinstalled with pip after creating a new venv and reinstalling tensorflow and pytorch. I also tried cleaning, uninstalling, and reinstalling conda based on advice from another forum. No dice.

Currently using:

Python 3.9.4
Tensorflow 2.7.0
PyTorch 1.10.0
Transformers 4.12.3
Streamlit 1.2.0

Any help greatly appreciated! Thanks :hugs:

it might be due to not having a requirements file. Here is an example of what your spaces app should have - flax-community/image-captioning at main try adding the requirements as they till the environment what packages to load. Hope this helps.

4 Likes

That worked perfectly. Thank you!

1 Like