Python|Python ImportError libGL.so.1 cannot open shared object file No such file or directory 解决方案

刚装的 linux 环境中使用 python 导入包时可能会报 libGL.so.1: cannot open shared object file 的错误,本文记录解决方案。
问题复现
【Python|Python ImportError libGL.so.1 cannot open shared object file No such file or directory 解决方案】我是在导入 opencv 包时遇到的错误:
>>> import cv2 Traceback (most recent call last): File "", line 1, in File "/root/anaconda3/envs/vvd_env/lib/python3.7/site-packages/cv2/__init__.py", line 5, in from .cv2 import * ImportError: libGL.so.1: cannot open shared object file: No such file or directory

问题原因
  • 缺少 libGL.so.1
解决方案
  • 把这个库装上:
sudo apt update sudo apt install libgl1-mesa-glx

参考资料
  • https://stackoverflow.com/questions/63544251/import-cv2-in-sagemaker-studio-jupyter-notebook-throws-importerror-libgl-so-1

    推荐阅读