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

ImportError: libGL.so.1: cannot open shared object file: No such file or directory #315

Open
1 of 2 tasks
yeldarby opened this issue Mar 10, 2024 · 2 comments
Open
1 of 2 tasks
Labels
bug Something isn't working

Comments

@yeldarby
Copy link
Contributor

Search before asking

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

Bug

If you install inside of Docker you need to ensure you have additional dependencies otherwise you get an error.

Ideally we should not require these (I think there's a headless version of cv2 we could use). Alternatively maybe we could catch this error and recommend the solve: apt-get update && apt-get install ffmpeg libsm6 libxext6 -y

Environment

root@C.10017133:/$ pip freeze | grep inference
inference-cli==0.9.15
inference-gpu==0.9.15
inference-sdk==0.9.15
root@C.10017133:/$ 

pytorch/pytorch:2.2.0-cuda12.1-cudnn8-devel docker with after running pip install inference-gpu

image

Minimal Reproducible Example

root@C.10017778:~$ inference benchmark python-package-speed -m "yolov8n-640"
Traceback (most recent call last):
  File "/usr/local/bin/inference", line 5, in <module>
    from inference_cli.main import app
  File "/usr/local/lib/python3.10/dist-packages/inference_cli/main.py", line 6, in <module>
    import inference_cli.lib
  File "/usr/local/lib/python3.10/dist-packages/inference_cli/lib/__init__.py", line 8, in <module>
    from inference_cli.lib.container_adapter import (
  File "/usr/local/lib/python3.10/dist-packages/inference_cli/lib/container_adapter.py", line 10, in <module>
    from inference_cli.lib.utils import read_env_file
  File "/usr/local/lib/python3.10/dist-packages/inference_cli/lib/utils.py", line 5, in <module>
    from supervision.utils.file import read_yaml_file
  File "/usr/local/lib/python3.10/dist-packages/supervision/__init__.py", line 9, in <module>
    from supervision.annotators.core import (
  File "/usr/local/lib/python3.10/dist-packages/supervision/annotators/core.py", line 4, in <module>
    import cv2
  File "/usr/local/lib/python3.10/dist-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/usr/local/lib/python3.10/dist-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
root@C.10017778:~$ D

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@yeldarby yeldarby added the bug Something isn't working label Mar 10, 2024
hvaria added a commit to hvaria/inference that referenced this issue Mar 16, 2024
Switching to opencv-python-headless addresses the libGL.so.1 error encountered in headless environments by eliminating the dependency on GUI-related libraries that OpenCV's standard version requires. The headless variant of OpenCV is specifically compiled without these graphical components, making it ideal for server or Docker environments where graphical interfaces are absent. This solution directly tackles the issue by removing the need for the missing libraries, rather than attempting to add unnecessary graphical support to a headless setup. It ensures that applications utilizing OpenCV for image processing or computer vision tasks can operate smoothly without encountering errors related to graphics libraries, thus maintaining functionality while adhering to the constraints of the deployment environment.
@PawelPeczek-Roboflow
Copy link
Collaborator

I've taken a look and not found an elegant solution for the problem. The PR opened by @hvaria suggest switch to headless opencv for CLI completely. The problems are the following:

  • there are installations where we resolve both cli requirements and core lib requirements - in presence of both, without libGL.so.1 being provided - even if there is no cv2.imshow(...) invocation - we have error - which would be the case in @yeldarby example (all libs installed) even with the change
  • CLI uses visualisation (inference infer command) - so we cannot completely eliminate standard OpenCV

We could probably do the following (tradeoffs, pros and cons that I see outlined)

  • have headless as a base requirement and have [desktop] extras in all libs and install standard cv on clients wish. Drawbacks:
    • people usually by default would try our lib in GUI-env - and would probably even use cv.imshow(...) to visualise, so asking them for additional effort may degenerate developer-experience
  • catching the error would be possible - may be not necessarily elegant, but could work. The core of that problem is not the fact that one cannot install standard CV without GUI - it's rather the fact of additional shared libs being required - so I am leaning towards that approach, if we cannot apply the next option
  • it seems that this problem could be completely avoided - and probably that should be done. If you analyse the series of imports leading to this error - you will discover that in inference_cli.lib.utils we import opencv through supervision (btw - it's headless by default and drags this into dependencies we install with inference) which is only used there due to read_yaml_file(...) util - which can be re-implemented or import could be pushed to another module. In long run - we shall think of developing CLI modules to be more command-oriented - to isolate potential domains of errors

@hvaria
Copy link
Contributor

hvaria commented Mar 18, 2024

I fully agree with your analysis and the outlined approach to navigate these complexities.

PawelPeczek-Roboflow added a commit that referenced this issue Mar 21, 2024
Updated requirements.cli.txt to resolve bug #315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants