6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Python / opencv-python] ImportError: libGL.so.1: cannot open shared object file の対策

Last updated at Posted at 2023-08-13

Env

Item Versionなど
docker image python:3.10-slim
opencv-python 4.8.0.76

事象

dockerコンテナ上での出来事。

Traceback (most recent call last):
  File "/root/.local/share/virtualenvs/opt-zvmYt2-H/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
  File "/opt/src/st_app.py", line 9, in <module>
    import cv2
  File "/root/.local/share/virtualenvs/opt-zvmYt2-H/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/root/.local/share/virtualenvs/opt-zvmYt2-H/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/local/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

対策

Dockerfile
RUN apt -y update
RUN apt -y install libopencv-dev

これで解決( ˙灬˙ ก)

公式ドキュメント

公式ドキュメントも貼っておく。
詳しくは見てないし、少なくとも今回は参考にすらしていないが、気にしている方もいると思うので。

参考記事

よく発生する問題らしく、他にもいろいろな対策記事がある。

どれかがうまくいかなくても、他で上手く行けばOK₍₍ (ง ˘ω˘ )ว ⁾⁾スヤッスヤッ

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?