Module Not Found Error "tensorflow" and "pytorch" for installed modules

Summary

Getting ā€œModule not Found errorā€ for 2 different model deployments, one for pytorch and one for tensorflow;
Even though both are installed in the system and the environment.

Error

Code snippet:

ModuleNotFoundError: No module named 'tensorflow'
Traceback:
File "C:\Python\Python311\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 564, in _run_script
    exec(code, module.__dict__)
File "C:\Users\utkar\omdena_paid\ZOWASELTEAMOMDENA\deployment\pesticide.py", line 2, in <module>
    import tensorflow as tf

Same for pytorch

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Expect to not have this error

Debug info

  • Streamlit version: 1.15.1
  • Python version: 3.10.9
  • Using venv
  • OS version:
  • Browser version: Chrome 108 on Windows 11

Requirements file

absl-py==1.3.0
astunparse==1.6.3
cachetools==5.2.0
certifi==2022.12.7
charset-normalizer==2.1.1
flatbuffers==22.12.6
gast==0.4.0
google-auth==2.15.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.51.1
h5py==3.7.0
idna==3.4
keras==2.11.0
libclang==14.0.6
Markdown==3.4.1
MarkupSafe==2.1.1
numpy==1.24.1
oauthlib==3.2.2
opt-einsum==3.3.0
packaging==22.0
protobuf==3.19.6
pyasn1==0.4.8
pyasn1-modules==0.2.8
requests==2.28.1
requests-oauthlib==1.3.1
rsa==4.9
six==1.16.0
tensorboard==2.11.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==2.11.0
tensorflow-estimator==2.11.0
tensorflow-intel==2.11.0
tensorflow-io-gcs-filesystem==0.29.0
termcolor==2.1.1
torch==1.13.1
typing_extensions==4.4.0
urllib3==1.26.13
Werkzeug==2.2.2
wrapt==1.14.1

Links

  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

Itā€™s a private repo, for which I donā€™t have the admin rights;
The error is from importing tensorflow and pytorch libraries the .py script but both are already installed.

Try making the first lines of your app be (before any other imports):

import streamlit as st
import subprocess

packages = str(subprocess.run('pip list', capture_output=True))
st.markdown(packages.replace('\\r\\n', '  \\\n'))

Then look and confirm that the environment you are using does indeed have the packages you think. For one, it looks like you used Python 3.11 in base and not an environment using Python 3.10 just from looking at the paths in the error message. So first make sure you are using the environment you think you are.

1 Like

Hey, thanks for the reply
I did add that code snippet and it did show the dependencies installed, but I wasnā€™t getting the TensorFlow error in fact there was some issue with protobuf this time so I fixed the protobuf and streamlit version and itā€™s working, for now, Iā€™ll update on the forum if I get some error again.

As for the version, I donā€™t why it was saying 3.11 I had switched to python 3.10 in base and environment as well and checked it with python --version,
But maybe that is what was causing the error because PyTorch and perhaps TensorFlow has a compatibility issue with python 3.11

1 Like

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