Hi everyone,
I am getting a ModuleNotFoundError when deploying my Streamlit app.
Error:
ModuleNotFoundError: No module named ‘torch’
Context:
- App runs locally without issue
- Fails when deployed on Streamlit Community Cloud
- Python version: 3.13
- Using Streamlit with PyTorch
What I have tried:
- Adding torch to requirements.txt
- Rebuilding the app
Questions:
- Does Streamlit Cloud support PyTorch with Python 3.13?
- Is there a recommended workaround or Python version to use?
Thanks in advance!
Welcome to the Streamlit community and thanks for your detailed question!
The error ModuleNotFoundError: No module named ‘torch’ on Streamlit Community Cloud usually means the torch package isn’t installed in the deployment environment. This often happens if the Python version is incompatible with the torch version specified, or if torch isn’t properly listed in requirements.txt.
Currently, PyTorch does not provide official wheels for Python 3.13, so installing torch on Streamlit Community Cloud with Python 3.13 will fail. The recommended workaround is to deploy your app using Python 3.10 or 3.11, which are supported by both Streamlit and PyTorch. You can set the Python version during deployment or in your app’s settings on the Streamlit Cloud dashboard. Make sure torch is included in your requirements.txt, and avoid using runtime.txt or .python-version files, as these are not respected by Streamlit Cloud for Python version selection. For more, see the official docs and related forum posts: Streamlit Docs: App dependencies, Forum: PyTorch install issues, Forum: Python version selection.
Sources: