I can’t run app with opencv-python or opencv-python-headless in streamlit cloud.
Even if I try to do something like this
import os
os.system(‘pip install opencv-python-headless’)
I got always this error:
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 "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
exec(code, module.__dict__)File "/mount/src/c_convert/c_convert.py", line 7, in <module>
import cv2
No is private and error is still the same 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 "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
exec(code, module.__dict__)File "/mount/src/c_convert/c_convert.py", line 7, in <module>
import cv2
Without seeing the actual code in the repo i cannot help. Most of the time this error is pretty trivial and you waste a lot of time guessing if you don’t see the code…
import streamlit as st
import cv2
import numpy as np
import os
st.header(‘Konwerter niebieskich stron zeskanowanych w formie pliku jpg’)
up_file = st.file_uploader(“Wybierz plik jpg”)
if up_file is not None:
file_name = os.path.splitext(up_file.name)[0]
# Read the images
file_bytes = np.asarray(bytearray(up_file.read()), dtype=np.uint8)
img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
# Resizing the image
image = cv2.resize(img, (1700, 2600))
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# Defining lower and upper bound HSV values
lower = np.array([0, 50, 50]) #[0, 50, 50]
upper = np.array([204, 255, 255]) #[204, 255, 255]
# Defining mask for detecting color
mask = cv2.inRange(hsv, lower, upper)
# Convert color on the image to black where we found blue
image[mask>0]=(192,192,192) #(51,0,0) is black (192,192,192) light grey
file_name_input = st.text_input('Tutaj możesz wprowadzić dowolną nazwę pliku po konwersji', file_name+'_B.jpg')
st.write('Nazwa pliku po konwersji to', file_name_input)
#cv2.imwrite(file_name_input,image)
#st.subheader('To jest wynik konwersji')
#st.image(file_name_input)
#st.download_button('Download gotowej wersji', file_name_input)
# Convert the processed image back to bytes
is_success, im_buf_arr = cv2.imencode(".jpg", image)
byte_im = im_buf_arr.tobytes()
# Display the processed image
st.subheader('To jest wynik konwersji')
st.image(byte_im, use_column_width=True)
# Provide a download button for the processed image
st.download_button('Download gotowej wersji', byte_im, file_name=file_name_input, mime='image/jpeg')
This is not my first app in streamlit cloud. The problem is, that I have to use another library: cv2 . And there is a problem with this library in streamlit cloud.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.