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

Using opencv + python in feedstocks now requires more opengl drivers #401

Closed
hmaarrfk opened this issue Mar 20, 2024 · 14 comments · Fixed by #429
Closed

Using opencv + python in feedstocks now requires more opengl drivers #401

hmaarrfk opened this issue Mar 20, 2024 · 14 comments · Fixed by #429
Labels

Comments

@hmaarrfk
Copy link
Contributor

hmaarrfk commented Mar 20, 2024

This is only a message for the linux builds. All other builds should be unaffected by this change.

Comment:

Since we added qt6-main as a dependency of opencv by "default", it is causing errors for downstream projects. I'm not sure if we can make these libraries "optional" at runtime for qt6 to help downstream projects "build" what they need without adding the OpenGL stuff.

https://github.com/conda-forge/opencv-feedstock/pull/396/files#diff-e36d294fb902698a9e5c5b991fd921efb1cfb09609fc4db4f94d72759c9e011a

the following packages should be added to the yum_requirements.txt file

mesa-libGL
mesa-libEGL
libglvnd-egl
libglvnd-glx
libglvnd-opengl

After adding these lines, one must rerender the recipe.

First reported in: #400 by @paugier (thank you for being patient)

Presently, I would suggest that in the test section, users that are facing this issue add:

test:
  requires:
    - libopencv *=headless*

Please do not specify a build string constraint for runtime requirements. It will override the run exports and restrict how users can use opencv in their system. Adding a requirement to the testing section is safe since it tests against the most reduced set of functionality.

For Ubuntu users and WSL+Ubuntu users:

apt-get install libglapi-mesa libegl-mesa0 libegl1 libopengl0 libgl1-mesa-glx
@hmaarrfk
Copy link
Contributor Author

cc: @conda-forge/qt-main

Cadair added a commit to Cadair/sunpy that referenced this issue Mar 20, 2024
Cadair added a commit to Cadair/sunpy that referenced this issue Mar 20, 2024
alasdairwilson pushed a commit to alasdairwilson/sunpy that referenced this issue Mar 21, 2024
alasdairwilson pushed a commit to alasdairwilson/sunpy that referenced this issue Mar 21, 2024
wtbarnes pushed a commit to sunpy/sunpy that referenced this issue Mar 21, 2024
wtbarnes pushed a commit to sunpy/sunpy that referenced this issue Mar 21, 2024
@glenn-jocher
Copy link

@hmaarrfk thanks for raising this issue, this has been exactly our problem for several weeks in https://github.com/conda-forge/ultralytics-feedstock with about a dozen patch updates failing to deploy.

Adding this line to tests resolves the build issues, but what about users installing our package without seeing this issue? Will their opencv installs fail without these additional opengl dependencies?

@hmaarrfk
Copy link
Contributor Author

Yeah, unfortunately i haven't had the chance to analyze this in detail.

I have 2 answer to this:

  1. The users deploying with docker + conda on the web should in general be able to benefit from this by adding the constraint to their build environments. The change that introduced the qt6 build also introduced a headless build that should start to avoid the qt5 inclusion (which was mandatory last week) and no in significantly small. I'm trying to add a noqt package so that users of headless machines can "ask conda" to forcibly not install qt5 or qt6 (saving space) but I would like more feedback.
  2. "Beginners" will likely be using Ubuntu or some other graphical Linux environment. So this shouldn't be noticeable for them.

If the above isn't really true, I'm happy to revisit (potentially marking linux builds with opencv+qt6 as broken, but this is somewhat drastic).

We could, maybe reconsider making the headless version the default one. But I think that would benefit "experts" more than beginners, which is somewhat against what brought me to conda in the first place.

Ultimately, this #293 (comment) comment is what I would like to do, but you know 3 years later and limited time has made this a nice to have.

I'm very interested in hearing user stories, without them, its hard to choose the right path.

@hmaarrfk
Copy link
Contributor Author

As a followup, from a historical prospective, it seems that things like mesa-libGl were added in the past to support the Qt5 graphical path in cv2

https://github.com/conda-forge/ultralytics-feedstock/blob/main/recipe/yum_requirements.txt

@paugier
Copy link

paugier commented Mar 28, 2024

@hmaarrfk

What about Windows? I now have the same type of issue on Windows (to build a new version of Fluidimage for conda-forge, conda-forge/fluidimage-feedstock#21)

import: 'cv2'
Traceback (most recent call last):
  File "D:\bld\fluidimage_1711573070427\test_tmp\run_test.py", line 2, in <module>
    import cv2
ImportError: DLL load failed while importing cv2: The specified module could not be found.

https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=904591&view=results

There is no headless version for Windows, so I cannot use this. I also tried to add the yum_requirements.txt but it does not help (for Windows).

@traversaro
Copy link
Contributor

@hmaarrfk

What about Windows? I now have the same type of issue on Windows (to build a new version of Fluidimage for conda-forge, conda-forge/fluidimage-feedstock#21)

import: 'cv2'
Traceback (most recent call last):
  File "D:\bld\fluidimage_1711573070427\test_tmp\run_test.py", line 2, in <module>
    import cv2
ImportError: DLL load failed while importing cv2: The specified module could not be found.

https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=904591&view=results

There is no headless version for Windows, so I cannot use this. I also tried to add the yum_requirements.txt but it does not help (for Windows).

I guess this is a different problem, tracked in conda-forge/graphite2-feedstock#14 . Quick workaround: conda install graphite2==1.3.13=1000

@pgunn
Copy link

pgunn commented Mar 29, 2024

This is breaking CI systems probably all over the place. I maintain a scientific piece of software and it's not as easy a fix for me because we don't want opencv to be headless (we use it for both maths and visualisations) but we also don't necessarily have the ability to install opengl on github test systems (or other places).

I'm not sure there is a good solution here, unless we can get the Qt developers to stop depending on OpenGL.

@hmaarrfk
Copy link
Contributor Author

This is breaking CI systems probably all over the place.

Yes I agree, though maybe the qt6 hard dependency on opengl is best discussed in: https://github.com/conda-forge/qt-main-feedstock/

we don't want opencv to be headless

To retain the old behavior of opencv on linux (requiring qt5) you would do

    - libopencv *=qt5*

However, I have to say that qt5 is somewhat hard to maintain. I've had to backport a difficult patch conda-forge/qt-main-feedstock#244 to enable modernizing it. So the qt6 transition is meant to help application like yours in the long run....

Will add the ubuntu dependency list to the top comment to help Ubuntu and WSL ubuntu users.

@giswqs
Copy link
Member

giswqs commented Mar 30, 2024

I just ran into the same issue. I have updated yum_requirements.txt, but still got the ImportError: libEGL.so.1: cannot open shared object file: No such file or directory. Any advice?

https://github.com/conda-forge/segment-geospatial-feedstock/pull/26/files

mesa-libGL
mesa-libEGL
libglvnd-egl
libglvnd-glx
libglvnd-opengl

image

@giswqs
Copy link
Member

giswqs commented Mar 30, 2024

Adding the following resolves the issue.

test:
  requires:
    - libopencv *=headless*  # [linux]
    - ```

@hmaarrfk
Copy link
Contributor Author

I just ran into the same issue. I have updated yum_requirements.txt, but still got the ImportError: libEGL.so.1: cannot open shared object file: No such file or directory. Any advice?

https://github.com/conda-forge/segment-geospatial-feedstock/pull/26/files


mesa-libGL

mesa-libEGL

libglvnd-egl

libglvnd-glx

libglvnd-opengl

You must rerender after this addition. I added this in the instructions.

@martibosch
Copy link

Hello,

I am encountering this issue too: conda-forge/detectree-feedstock#4

However, I am only using opencv to peform convolutions, i.e., the cv2.filter2D method, so I suppose that I do not need all the qt/graphics dependencies. Therefore, if I understand correctly from #293, in order to keep the conda package as small as possible, I could change opencv for opencv-headless in the run requirements of my recipe and then I would not need to add the yum_requirements.txt file? Does this make sense?

Thank you. Best,
Martí

@hmaarrfk
Copy link
Contributor Author

hmaarrfk commented Apr 1, 2024

thank you for asking the question.

Do not change the run requirements as it would conflict with other packages that may require opencv's GUI freature in your end user's final environment.

Rather simply add a headless constraint to your test section. I made a suggestion to your feedstock.

@martibosch
Copy link

Thank you @hmaarrfk! I applied your suggestion, tests passed and I could already merge the PR 🚀

@hmaarrfk hmaarrfk pinned this issue Apr 21, 2024
weiji14 added a commit to regro-cf-autotick-bot/mmcv-recipe-feedstock that referenced this issue May 21, 2024
weiji14 added a commit to conda-forge/mmcv-recipe-feedstock that referenced this issue May 22, 2024
* updated v2.2.0

* MNT: Re-rendered with conda-build 24.3.0, conda-smithy 3.34.1, and conda-forge-pinning 2024.04.24.14.42.55

* Configure Azure to free disk space

Xref conda-forge/cudatoolkit-feedstock#91

* Reset build number to 0

* MNT: Re-rendered with conda-build 24.3.0, conda-smithy 3.34.1, and conda-forge-pinning 2024.04.26.17.13.40

* Disable pip check because mmengine-lite is installed

See #29 (comment)

* Rebuild for python312

* MNT: Re-rendered with conda-build 24.3.0, conda-smithy 3.36.0, and conda-forge-pinning 2024.05.21.18.33.22

* Add mesa-libEGL et al. to yum_requirements.txt

Xref conda-forge/opencv-feedstock#401

* MNT: Re-rendered with conda-build 24.3.0, conda-smithy 3.36.0, and conda-forge-pinning 2024.05.21.18.33.22

---------

Co-authored-by: Wei Ji <[email protected]>
Co-authored-by: conda-forge-webservices[bot] <91080706+conda-forge-webservices[bot]@users.noreply.github.com>
@hmaarrfk hmaarrfk unpinned this issue Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants