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 #32

Closed
weiji14 opened this issue Apr 13, 2022 · 3 comments
Closed

ImportError: libGL.so.1: cannot open shared object file #32

weiji14 opened this issue Apr 13, 2022 · 3 comments

Comments

@weiji14
Copy link
Contributor

weiji14 commented Apr 13, 2022

Hi there, just starting to try out Planetary Computer and it's working pretty well so far! Just bumped into this issue though when trying to import opencv (which is a dependency on one of the packages I'm using).

Specifically, the error is ImportError: libGL.so.1: cannot open shared object file: No such file or directory. Looking at https://stackoverflow.com/questions/55313610/importerror-libgl-so-1-cannot-open-shared-object-file-no-such-file-or-directo, it seems like there's some package that needs to be installed.

Minimal working example to reproduce, do in a terminal:

mamba install opencv

then in a Jupyter notebook, try:

import cv2

produces

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [1], in <module>
----> 1 import cv2

File /srv/conda/envs/notebook/lib/python3.8/site-packages/cv2/__init__.py:8, in <module>
      5 import importlib
      6 import sys
----> 8 from .cv2 import *
      9 from .cv2 import _registerMatType
     10 from . import mat_wrapper

ImportError: libGL.so.1: cannot open shared object file: No such file or directory
@TomAugspurger
Copy link

Thanks for opening this. Apparently our docker image doesn't have system requirement that conda / opencv is expecting (libgl).

Unfortunately, there isn't anything you can easily do as a user to get that installed. I believe it has to be in the docker image before the notebook server starts up. This downside of adding this to the docker image is that it'll increase the size, which will cause slower spawn times.

Which library / libraries were you trying to use? Perhaps there's an implementation of what you're trying to do in one of the packages currently installed.

@weiji14
Copy link
Contributor Author

weiji14 commented Apr 14, 2022

Hi Tom, thanks for the quick reply! Yes I think you're right that libgl needs to be installed and that's not something that works with a simple mamba install.

I was trying to run an object detection neural network model implemented in mmdet that relies on mmcv which imports opencv under the hood. Have also tried to export the Pytorch model to ONNX to see if I can get it to run using onnxruntime but there's something in the architecture that makes it a bit tricky. I'll see if I can find a workaround that avoids having to import opencv, or maybe just find another neural network architecture that works off the shelf.

@weiji14
Copy link
Contributor Author

weiji14 commented Apr 15, 2022

Ok, I'll close this issue as I've managed to find a few workarounds. For anyone interested, these are possible solutions (some which need to be done in combination):

  1. Use pip install opencv-python-headless, see https://pypi.org/project/opencv-python-headless for details
  2. Export the neural network model to ONNX format and run it using onnxruntime to avoid having to import cv2. See e.g. https://pytorch-lightning.readthedocs.io/en/1.6.0/common/production_inference.html#convert-to-onnx. Turns out I just needed to use a higher opset (14) than the default (11?) to handle the fancy layers
  3. Load the model directly using Pytorch Hub, which works if you're using a fairly standard model, but might not fit all projects.

Actually have a separate problem getting onnxruntime to work with the GPU, but will open a separate issue to track things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants