Module not found error during deployment

Hi everyone,
I am glad I have joined the community; I am also new to programming; It is my first time trying to deploy an app, but I keep on getting the following error; ModuleNotFoundError:
This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).
Traceback:
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 535, in _run_script
exec(code, module.dict)
File “/mount/src/improved-sniffle/Deployment_1.py”, line 8, in
import joblib
I have gone back to my virtual environment to see if I have the packages installed and yes they are already installed. I have restarted the kernel, but i keep on getting the same error.
My app is on: https://improved-sniffle-gfxfjw9yvx9tja2d8sb9hr.streamlit.app/
My Github repository: GitHub - carolmatlala/improved-sniffle: Topic classifier for news articles
Python: 3.11.5 Anaconda
Streamlit: 1.31.1

2 Likes

Streamlit Cloud knows nothing about your local virtual environment. You need to tell Streamlit Cloud to install the packages too. You usually use a requirements file for that.

Find more information in this article from the documentation and the resources linked there.

2 Likes

Hi @carolmatlala . Welcome to streamlit community.
You need to create an new file requirements.txt in your GitHub as follows:-

streamlit
joblib
numpy

Note:- Don’t forget to reboot the app after adding the requirements.txt file.

2 Likes

Even then it will still not work because there are paths to local files in the code…

2 Likes

I have the same problem for another library, I have added the requirements.txt file as well but it still is not working.
My error is as follows →
ModuleNotFoundError: No module named ‘google.generativeai’

2024-02-23 13:38:23.528 503 GET /script-health-check (10.12.30.40) 121.77ms

2024-02-23 13:38:28.385 Uncaught app exception

Traceback (most recent call last):

File “/home/adminuser/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 535, in _run_script

exec(code, module.__dict__)

File “/mount/src/ml_project/marcusST.py”, line 3, in

import marcus

File “/mount/src/ml_project/marcus.py”, line 4, in

import google.generativeai as genai
2 Likes

There might be something wrong with your requirements file.

2 Likes

Add the Google generative ai package in requirement. Reboot the app

1 Like

Hi @carolmatlala

As others had pointed out, you can add prerequisite libraries in the requirements.txt file and it this case, in addition to your other dependencies, you can add google-generativeai to the file.

For further information, we actually have an FAQ about this topic – please check it out: FAQ: ModuleNotFoundError.

Happy Streamlit-ing! :balloon:

Hey Franky,
How do you suggest I deal with the paths to local files…?

1 Like

Thank ya!

2 Likes

I have been reading some comments where some were suggesting that the requirements file is not necessary. But I’ll definitely add it together with the google-generative Ai.
Thanks a lot.

1 Like

Unfortunately, this is not correct. As soon as you need dependencies outside of Streamlit, you need a requirements file (or equivalent) for the deployment on streamlit cloud.

https://docs.streamlit.io/streamlit-community-cloud/deploy-your-app/app-dependencies

1 Like
  • put these files also into github
  • make the file paths relative in your code
1 Like

this is my requirements.txt file

1 Like

No, I used it in my local host implementation of Streamlit and the same program did work seamlessly.

This is my requirement.txt file

1 Like

Many things can go wrong that cannot be seen in these matrices of pixels.

You may need to reboot or redeploy your app after making changes to requirements.txt.

1 Like

HI Goyo, you are right, the problem was that I had to give a full reboot. This problem is solved now.
Sorry for not updating about it earlier as I moved forward and forgot to mention it.

1 Like

Thank you. I have managed to save the requirements text file. What path do I use to store files in the Github Repo?

You need to save the requirements.txt in a place where the main file is located. For example:-

Your GitHub repo

app.py
any_folders
requirements.txt

Hope you understood

Happy Streamlit-ing :balloon:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.