Problem error import CV2

Hi:

My streamlit app runs fine locally. I am doing image processing hence using opencv
But when I deploy the app it says :

note: This error originates from a subprocess, and is likely not a problem with pip.
  Building wheel for blinker (setup.py): started
  ERROR: Failed building wheel for opencv-python-headless
  Building wheel for blinker (setup.py): finished with status 'done'
  Created wheel for blinker: filename=blinker-1.4-py3-none-any.whl size=13478 sha256=d68f921990555798c44380592087304862ce2c05af5826d0bb78a7b790950ba1
  Stored in directory: /tmp/pip-ephem-wheel-cache-vc3hqmkx/wheels/50/93/f8/4f0a42a03a06626d675f13907b6982ad5ecff383530af5a900
  Building wheel for validators (setup.py): started
  Building wheel for validators (setup.py): finished with status 'done'
  Created wheel for validators: filename=validators-0.20.0-py3-none-any.whl size=19582 sha256=e27f962b0bfe279b95e7f3d2e7c79f3eb6f3e4240e690c4d27ef9e532af307aa
  Stored in directory: /tmp/pip-ephem-wheel-cache-vc3hqmkx/wheels/2d/f0/a8/1094fca7a7e5d0d12ff56e0c64675d72aa5cc81a5fc200e849
Successfully built numpy blinker validators
Failed to build opencv-python-headless
ERROR: Could not build wheels for opencv-python-headless, which is required to install pyproject.toml-based projects

I adjust according the recommendations forums before opencv but doesnt work

The entire code is on my github here is the link: GitHub - mcastiblanco1251/CV: Tratamiento de Imagenes
Any help is appreciated
Thanks

Use in your requirements.txt file:

opencv-python-headless==4.5.4.60
1 Like

Now it appear this:

ERROR: Cannot install -r /app/cv/requirements.txt (line 2), -r /app/cv/requirements.txt (line 4) and numpy==1.18.1 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested numpy==1.18.1
    pandas 1.1.5 depends on numpy>=1.15.4
    opencv-python-headless 4.5.4.60 depends on numpy>=1.19.3

Remove (or update) the version numbers of pandas and numpy packages, unless you need specifically these older versions.

1 Like

Thks very much!!

Now I have this error:

cv2.error: OpenCV(4.5.4) /tmp/pip-req-build-9vck9bv0/opencv/modules/highgui/src/window.cpp:1268: error: (-2:Unspecified error) The function is not implemented.

Do you have a any idea that how solve it?

You cannot use e.g. cv2.VideoCapture, cv2.imshow, cv2.waitKey, if streamlit runs on a hosted service!

This does not work because there is a fundamental misunderstanding about how Streamlit works.
Streamlit consists of a frontend and backend part. Any interaction with streamlit must be done via the browser or browser APIs. Anything trying to bypass this, may work on your local computer, but will fail as soon as streamlit is hosted, i.e. streamlit no longer runs on the same computer as the browser.

What happens when you try to open cv2 (or other) gui widgets or try to access video hardware? They will be opened on the computer on which the python application is running. But there is neither an UI nor a graphics driver nor a video device on streamlit cloud and even if there was, it would be the wrong computer.

You have to rethink your whole approach, it will not work this way.

1 Like

I got it, thanks again!!!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.