Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opencv-headless requirement breaks existing installation #351

Closed
1 of 2 tasks
adrianboguszewski opened this issue Sep 4, 2023 · 23 comments
Closed
1 of 2 tasks

opencv-headless requirement breaks existing installation #351

adrianboguszewski opened this issue Sep 4, 2023 · 23 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@adrianboguszewski
Copy link

Search before asking

  • I have searched the Supervision issues and found no similar bug report.

Bug

Supervision >= 0.12.0 requires opencv-headless. If I use opencv-python in my application and then install supervision, my opencv is broken (overwritten by the headless package).
It would be nice to configure it somehow not to install opencv-headless if any opencv package already installed.

Environment

This happens for supervision >= 0.12.0
Ubuntu 22.04
Python 3.10

Minimal Reproducible Example

pip install opencv-python
pip install supervision==0.14.0

import cv2
import numpy as np
arr = np.zeros((10, 10), dtype=np.uint8)
cv2.imshow("img", arr)

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@adrianboguszewski adrianboguszewski added the bug Something isn't working label Sep 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2023

Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap.

@onuralpszr onuralpszr self-assigned this Sep 4, 2023
@onuralpszr
Copy link
Collaborator

@adrianboguszewski for workaround you can delete headless and reinstall full and use with full version and that would work. I can make them explicitly separated and ask install one of them but if you just install supervision it won't have any opencv so we can change our install to force either let's say "headless" and "full" like "pip install supervision[full]" but If you also try to install headless it will skip supervision but install headless in the of the day. So in the end of the day user also has to choose one of them and make sure not have both or delete one them.

@adrianboguszewski
Copy link
Author

Yeah, that's what I did as a workaround. But also, I'm thinking about the mature solution. I don't know if there is any way to check opencv has been already installed so more research is needed.

I think your proposition isn't bad. Let's say the default version is headless and if the user wants to have full opencv they must go with pip install supervision[full]

@onuralpszr
Copy link
Collaborator

I think your proposition isn't bad. Let's say the default version is headless and if the user wants to have full opencv they must go with pip install supervision[full]

That is the default right now. But problem is full bring headless too.

@onuralpszr
Copy link
Collaborator

Also related : python-poetry/poetry#6419 and not exist yet. So most possible option I see separate both and install one but user has to delete if there is both and we need to as a warning sign as well.

@onuralpszr
Copy link
Collaborator

@SkalskiP I know how we do it. So I think we should document at least for conflict problem between headless and full and maybe we can reconsider separate but warning is clear (just install "pip install supervision" won't be enough anymore.

@onuralpszr
Copy link
Collaborator

@hardikdava could you please put your input as well ? I am thinking about 2 ways but I wanna talk through as well.

@onuralpszr onuralpszr added the question Further information is requested label Sep 5, 2023
@hardikdava
Copy link
Collaborator

hardikdava commented Sep 5, 2023

@onuralpszr I would suggest to do as following:

Install supervision with normal opencv package:
pip install supervision  

Install supervision with opencv-headless
pip install supervision[headless]

Main reason is that most of the uses uses supervision for dataset conversion and annotators which requires GUI (from normal opencv package).

@onuralpszr
Copy link
Collaborator

onuralpszr commented Sep 5, 2023

that is the current but problem is they need to delete headless opencv if they started like that*

@dennis-ciancoders
Copy link

@adrianboguszewski for workaround you can delete headless and reinstall full and use with full version and that would work.

The thing is that's not possible when using Poetry instead of pip:

poetry remove opencv-python-headless                                                       

The following packages were not found: opencv-python-headless

When using Poetry the workaround is to uninstall opencv-python-headless after installing supervision using pip... wich will "fix" the problem but totally not a good solution.

poetry install "supervision[desktop]"

poetry shell

pip uninstall opencv-python-headless

@SkalskiP
Copy link
Collaborator

@onuralpszr is that problem still active?

@Buckler89
Copy link

Buckler89 commented Jul 31, 2024

@onuralpszr is that problem still active?

yes.
For me the solution suggested by @dennis-ciancoders broke imshow and waitKey methods of opencv.

Someoneelse is encountering the same issue?

@onuralpszr
Copy link
Collaborator

@onuralpszr is that problem still active?

yes. For me the solution suggested by @dennis-ciancoders broke imshow and waitKey methods of opencv.

Someoneelse is encountering the same issue?

Quick workaround

pip install supervision
pip uninstall opencv-python-headless
pip install opencv-python

This should work. You uninstall headless and install full one and you can make it work. Make sure you delete headless and install opencv-python, If somehow you have both installed then delete both and install "opencv-python" should work. Let me know how is it go.

@SkalskiP
Copy link
Collaborator

SkalskiP commented Aug 6, 2024

Hi @onuralpszr 👋🏻 Do we have any ideas on how to improve desktop / headless installs? If not, I suggest we close this issue.

@onuralpszr
Copy link
Collaborator

Hi @onuralpszr 👋🏻 Do we have any ideas on how to improve desktop / headless installs? If not, I suggest we close this issue.

@SkalskiP hello 👋

2 suggestions, I will explicit documentation how to manage properly those cases and not do change on toml, second I will remove headless and put desktop package and I will wrote documentation again to how to switch between them and explain how to manage desktop and headless, based on these I can create pr and we can put marl as complete?

@SkalskiP
Copy link
Collaborator

SkalskiP commented Aug 7, 2024

Sounds good. Would you like to work on this PR?

@onuralpszr
Copy link
Collaborator

Sounds good. Would you like to work on this PR?

Sure let me write based on option one then ?

@tkelestemur-bdai
Copy link

Hello, has there been any update on this? I'm trying to use opencv functions alongside the supervision but that's impossible because headless opencv is overwriting cv2 functions. For example, I can't run cv.imshow(...). If I uninstall opencv-python-headless, then I'm getting the following error:

(vpl) tkelestemur_theaiinstitute_com@tkelestemur-ubuntu2204-l4x1-1024gb:~/visuomotor/visuomotor/perception$ python samv2.py
Traceback (most recent call last):
  File "/home/tkelestemur_theaiinstitute_com/visuomotor/visuomotor/perception/samv2.py", line 8, in <module>
    import supervision as sv
  File "/home/tkelestemur_theaiinstitute_com/venvs/vpl/lib/python3.10/site-packages/supervision/__init__.py", line 9, in <module>
    from supervision.annotators.core import (
  File "/home/tkelestemur_theaiinstitute_com/venvs/vpl/lib/python3.10/site-packages/supervision/annotators/core.py", line 21, in <module>
    from supervision.draw.utils import draw_polygon
  File "/home/tkelestemur_theaiinstitute_com/venvs/vpl/lib/python3.10/site-packages/supervision/draw/utils.py", line 164, in <module>
    text_font: int = cv2.FONT_HERSHEY_SIMPLEX,
AttributeError: module 'cv2' has no attribute 'FONT_HERSHEY_SIMPLEX'

@LinasKo
Copy link
Contributor

LinasKo commented Sep 18, 2024

We'll look into it this release. It's about time we fixed it.

@onuralpszr
Copy link
Collaborator

#1530 merged and close as complete

@LinasKo
Copy link
Contributor

LinasKo commented Sep 19, 2024

Hi @tkelestemur-bdai,

The issue is fixed on development branch. You can install it with pip install git+https://github.com/roboflow/supervision.git@develop.

This will be added to the main package in the next release, at around 4th of October.

@Kutayykilic
Copy link

Kutayykilic commented Oct 22, 2024

Hi @tkelestemur-bdai,

The issue is fixed on development branch. You can install it with pip install git+https://github.com/roboflow/supervision.git@develop.

This will be added to the main package in the next release, at around 4th of October.

So about that, while on a pre existing environment that I was using, (ultralytics docker image), installing supervision on that docker image makes opencv break again, (circular import errors) and cv2.HERSHEY etc.

I dealt with this a few months ago as well, the best solution was to install supervision without any extra dependencies, pip install supervision --no-deps solved all the issues for me, except that you have to only install defused xml by yourself. I am sharing this comment in case if anyone needs it

Edit: I forgot to mention that I have been testing this with 0.24( the latest version released)

@LinasKo
Copy link
Contributor

LinasKo commented Oct 22, 2024

Thank you @Kutayykilic !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

9 participants