Repository: opencv
Issue: ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Labels: invalid,question (invalid tracker)

### System Information

I work on an EC2 instance which has linux background. My Python version is 3.12.4. Other relevant packages that might be useful are:

```
langchain==0.2.11
langchain-community==0.2.1
langchain-core==0.2.26
langchain-openai==0.1.20
langchain-text-splitters==0.2.0
langchainhub==0.1.20
opencv-contrib-python-headless==4.8.0.76
opencv-python==4.10.0.84
opencv-python-headless==4.8.0.76
python-dateutil==2.9.0.post0
python-docx==1.1.2
python-dotenv==1.0.1
python-iso639==2024.4.27
python-magic==0.4.27
python-multipart==0.0.9
python-oxmsg==0.0.1
python-pptx==0.6.23
unstructured==0.15.0
unstructured-client==0.25.1
unstructured-inference==0.7.36
unstructured.pytesseract==0.3.12
```

### Detailed description

I am trying to load a folder with PDFs using LangChain's `DirectoryLoader` but am facing libGL1 not found. 

I've tried uninstalling/installing OpenCV/OpenCV headless following Stackoverflow discussions but nothing seems to work!

On the other hand, other loaders like `PubMedLoader` and `WebBaseLoader` seems to work fine (not sure if they are hitting this endpoint!)

Here's the error log - 
```
Error loading file /home/ec2-user/sandbox/IntelliFix/satya/CT_sample/CT/Frontier-Maxima/ServiceManuals/5229839-100.pdf
Traceback (most recent call last):
  File "/home/ec2-user/sandbox/IntelliFix/satya/rag_eval.py", line 5, in <module>
    docs = loader.load()
           ^^^^^^^^^^^^^
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/langchain_community/document_loaders/directory.py", line 117, in load
    return list(self.lazy_load())
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/langchain_community/document_loaders/directory.py", line 182, in lazy_load
    yield from self._lazy_load_file(i, p, pbar)
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/langchain_community/document_loaders/directory.py", line 220, in _lazy_load_file
    raise e
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/langchain_community/document_loaders/directory.py", line 210, in _lazy_load_file
    for subdoc in loader.lazy_load():
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/langchain_community/document_loaders/unstructured.py", line 88, in lazy_load
    elements = self._get_elements()
               ^^^^^^^^^^^^^^^^^^^^
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/langchain_community/document_loaders/unstructured.py", line 168, in _get_elements
    from unstructured.partition.auto import partition
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/unstructured/partition/auto.py", line 78, in <module>
    from unstructured.partition.pdf import partition_pdf
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/unstructured/partition/pdf.py", line 54, in <module>
    from unstructured.partition.pdf_image.analysis.bbox_visualisation import (
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/unstructured/partition/pdf_image/analysis/bbox_visualisation.py", line 16, in <module>
    from unstructured_inference.inference.layout import DocumentLayout
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/unstructured_inference/inference/layout.py", line 15, in <module>
    from unstructured_inference.inference.layoutelement import (
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/unstructured_inference/inference/layoutelement.py", line 7, in <module>
    from layoutparser.elements.layout import TextBlock
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/layoutparser/elements/__init__.py", line 16, in <module>
    from .layout_elements import (
  File "/home/ec2-user/anaconda3/envs/langchain/lib/python3.12/site-packages/layoutparser/elements/layout_elements.py", line 25, in <module>
    from cv2 import getPerspectiveTransform as _getPerspectiveTransform
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
```

**P.S**: Raised an [issue](https://github.com/langchain-ai/langchain/issues/25029) in LangChain as well to understand if the issue is in their library.

### Steps to reproduce

The following code throws an import error!

```
from langchain_community.document_loaders import DirectoryLoader
loader = DirectoryLoader("path-to-directory-where-pdfs-are-present")
docs = loader.load()
```

while the below one seems to work fine ---
```
from langchain_community.document_loaders import DirectoryLoader
loader = PubMedLoader("...")
docs = loader.load()
```

### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [X] I updated to the latest OpenCV version and the issue is still there
- [X] There is reproducer code and related data files (videos, images, onnx, etc)