`I’m deploying a Streamlit app on Streamlit Cloud that uses PyTorch and Torchvision for image segmentation.
Locally, everything works fine, but when I deploy on Streamlit Cloud I get this error:
File "/home/adminuser/venv/lib/python3.9/site-packages/torchvision/transforms/functional.py", line 166, in to_tensor
img = torch.from_numpy(np.array(pic, mode_to_nptype.get(pic.mode, np.uint8), copy=True))
RuntimeError: Numpy is not available
Repository link : https://github.com/Khushi-51/AI_SpillGuard_OSD-Khushi
Minimal example that fails on Streamlit Cloud:
import torch
import numpy as np
print("Torch sees NumPy:", torch.tensor(\[1.0, 2.0\]).numpy())
What I tried
My requirements.txt originally looked like this:
torch==2.0.1
torchvision>=0.15.2
numpy>=1.21.0
pillow>=8.3.0
gdown>=4.7.1
opencv-python>=4.5.0
...
I already added NumPy to requirements.txt.
Tried reordering so NumPy is installed before torch.
Cleared .venv and cached builds in Streamlit Cloud.
Tried Rebuild Environment from Streamlit Cloud settings.
Works perfectly locally with streamlit run app.py.
Still, the deployed app throws RuntimeError: Numpy is not available`