Software⏱️ 2 min read📅 2026-05-30

How to Fix: ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Error importing OpenCV in Docker due to missing libGL.so.1 file.

Quick Answer: Try installing the latest version of libgl1-mesa-glx using apt-get update && apt-get install -y libgl1-mesa-glx, or consider using a different GPU driver if available.

To resolve the ‘ImportError: libGL.so.1: cannot open shared object file: No such file or directory’ issue in Docker while trying to import OpenCV, you need to modify your environment variables.

🚀 How to Resolve This Issue

Method 1: Set Environment Variable

  1. Step 1: Run the following command in your Docker container to set the environment variable:
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu

Step 2:

After setting the environment variable, you can try importing OpenCV again. If it still doesn’t work, proceed to Method 2.

Method 2: Install libgl1-mesa-glx

  1. Step 1: Run the following command in your Docker container to install libgl1-mesa-glx:
apt-get update && apt-get install -y libgl1-mesa-glx

Step 2:

After installing libgl1-mesa-glx, you can try importing OpenCV again. If it still doesn’t work, check your Docker container logs for any errors.

💡 Conclusion

By following these steps, you should be able to resolve the ‘ImportError: libGL.so.1: cannot open shared object file: No such file or directory’ issue in Docker while trying to import OpenCV.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions