No module named 'tensorflow'

i got error message No module named ‘tensorflow’, this is my requiremnent.txt file content
beautifulsoup4==4.12.2
keras==2.12.0
matplotlib==3.7.2
numpy==1.24.3
pandas==1.5.3
Requests==2.31.0
scikit_learn==1.2.2
streamlit==1.26.0
tensorflow==2.12.0
openpyxl==3.1.2
cryptocmd==0.6.4
xlsxwriter==3.1.1

This is the log
2024-02-08 17:00:42.035 Uncaught app exception
Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 565, in _run_script
exec(code, module.dict)
File “/mount/src/cryptocurrency-predicition-app/project/main.py”, line 9, in
from keras.models import load_model
File “/home/adminuser/venv/lib/python3.11/site-packages/keras/init.py”, line 21, in
from keras import models
File “/home/adminuser/venv/lib/python3.11/site-packages/keras/models/init.py”, line 18, in
from keras.engine.functional import Functional
File “/home/adminuser/venv/lib/python3.11/site-packages/keras/engine/functional.py”, line 24, in
import tensorflow.compat.v2 as tf
ModuleNotFoundError: No module named ‘tensorflow’
2024-02-08 17:00:42.186 503 GET /script-health-check (10.12.48.32) 169.23ms

1 Like

Try rebooting your app.

1 Like

I already did it, i even deleted my app and deploy it again and still get the same results

1 Like

Hi @Baghas_Wahyu . Just mention only the following packages in your requirements.txt as follows:-

tensorflow
streamlit
#resr of your packages except matplotlib, numpy, scikit learn and keras

Hope it will works.
Happy Streamlit-ing :balloon:

1 Like

tensorflow==2.12.0 depends on numpy<1.2 so you cannot install numpy==1.24.3 at the same time. This information is available in the application logs.

1 Like

i changed my requirments.txt file into this and yet same error

beautifulsoup4
pandas
Requests
streamlit
tensorflow
openpyxl
cryptocmd
xlsxwriter

1 Like

after i removed specified version numpy it still get same error

Hi @Baghas_Wahyu

Could you try out with a small subset of libraries and then incrementally add the others afterwards (also make sure to reboot the app afterwards to ensure that the library gets installed).

Your requirements.txt works for me. Sometimes streamlit cloud doesn’t pick the changes to requirements.txt until you reboot or redeploy the application.

that means i have to add library one by one is it correct?

It’s something that I would typically try if the bulk of libraries provided in requirements.txt file does not work. This would help to rule out which one works and which one does not.

As also mentioned earlier, it’s also worth trying to reboot the app after changes is made to the requirements.txt file in order to ensure that it gets installed.

@Goyo confirmed that your requirements.txt works, perhaps you can try rebooting the app.

Hope this helps

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