Deployment Error: ModuleNotFoundError: No module named 'cv2'
1. Description
I’m trying to deploy a Streamlit app that uses OpenCV (cv2). The app works locally but fails on Streamlit Community Cloud with a ModuleNotFoundError. I believe it may be due to Python version compatibility with opencv-contrib-python.
2. Deployment Details
a. Is it deployed on Community Cloud?
Yes
b. Public app link:
https://helmet-numberplate-detection.streamlit.app/
3. GitHub Repository
4. Full Error Message
vbnet
CopyEdit
ModuleNotFoundError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).
Traceback:
File "/mount/src/helemet_detection_numberplate/streamlit_app.py", line 4, in <module>
import cv2
5. Environment Info
- Streamlit version:
1.41.1 - Python version:
3.12.1
6. Additional Info
- My
requirements.txtincludes:
nginx
CopyEdit
streamlit
opencv-contrib-python==4.9.0.80
ultralytics
numpy
pillow
easyocr
imutils
- I also created a
packages.txtfile with:
nginx
CopyEdit
libgl1
Suspected Cause
From logs, it seems Streamlit Cloud is installing a Python version (like 3.13 or 3.12) that is not yet compatible with opencv-contrib-python==4.9.0.80. The package silently fails to install, leading to cv2 not being found.
What I’ve Tried
- Verified
requirements.txtandpackages.txt - Rebuilt app
- Still encountering
cv2import error
Request
Can someone confirm:
- Whether Python 3.12/3.13 is supported with
opencv-contrib-python - If a
runtime.txtfile (e.g.python-3.11) can help resolve this?
Thank you!
