ImportError: libGL.so.1: cannot open shared object file解决

How to Fix the Error

1.1. Install the Required Library (Ubuntu/Debian-based Systems)

Run the following command to install the missing library:

1
2
sudo apt update
sudo apt install libgl1

1.2. For CentOS/RHEL/Fedora

1
2
sudo yum install mesa-libGL  # For older CentOS/RHEL
sudo dnf install mesa-libGL # For Fedora/newer RHEL-based systems

1.3. For Arch Linux

1
sudo pacman -S mesa

1.4. If Using Docker

If you’re running this inside a Docker container, ensure the required libraries are installed in your Dockerfile:

1
RUN apt-get update && apt-get install -y libgl1

1.5. Check for 32-bit vs 64-bit Issues

If you’re running a 32-bit application on a 64-bit system, you may need:

1
sudo apt install libgl1:i386  # For Debian/Ubuntu