0

`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`

1 Answer 1

0
  • Place numpy at top with specific version
  • Then don't use == for numpy and torchvision
  • PyTorch 2.0.1 works with Numpy 1.21.x - 1.24.x

Now, requirement.txt should look like

numpy==1.24.0
torch==2.0.1
torchvision==0.15.2
....
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.