20

Essentially, trying to write the following code results in the error below:

Code

from matplotlib import pyplot as plt
plt.plot([1,2,3,2,1])
plt.show()

Error

libGL error: MESA-LOADER: failed to open iris: /home/xxx/.conda/envs/stat/lib/python3.8/site-packages/pandas/_libs/window/../../../../../libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/lib64/dri/iris_dri.so) (search paths /usr/lib64/dri, suffix _dri)
libGL error: failed to load driver: iris
libGL error: MESA-LOADER: failed to open swrast: /home/xxx/.conda/envs/stat/lib/python3.8/site-packages/pandas/_libs/window/../../../../../libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /usr/lib64/dri/swrast_dri.so) (search paths /usr/lib64/dri, suffix _dri)
libGL error: failed to load driver: swrast

I found similar errors on StackOverflow but none were what is needed here.

Mahyar Mirrashed
  • 471
  • 1
  • 3
  • 14

3 Answers3

43

The solution proposed by Mahyar Mirrashed is working for me. On my system (Ubuntu 22.04) the libstdc++.so.6 file is located in /usr/lib/x86_64-linux-gnu/libstdc++.so.6 To know where to find this file I suggest to run the following command :

find / -name libstdc++.so.6 2>/dev/null

which resulted with files from miniconda, snap and /usr/lib/... I added the export LD_PRELOAD to my .bashrc file and it's working fine.

export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
Kevin Marchais
  • 531
  • 1
  • 4
  • 3
  • 5
    Thanks. This worked for me. I am running Ubuntu 22.04 LTS. – mhdadk May 29 '22 at 22:23
  • Thank you. This worked for me on Linux Mint 21, intel driver with a similar problem. – Manu Feb 20 '23 at 18:48
  • Thanks, it works on mine. As additions, we can also set environment variable when starting conda environment, so we don't need set it manually every time: https://stackoverflow.com/a/62508395/1219992 – Yusuf Irzan Aug 02 '23 at 15:03
  • This did not work for me. I did export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 and am still seeing the error libGL error: failed to load driver: iris – Adam Aug 22 '23 at 20:21
  • @Adam did the first line that I suggested give you this exact path? – Kevin Marchais Aug 24 '23 at 16:10
  • @KevinMarchais what ended up working for me was running `conda install -c conda-forge libffi`. – Adam Aug 24 '23 at 18:11
28

Installing libstdcxx-ng from conda-forge should solve this problem.

Command:

conda install -c conda-forge libstdcxx-ng
Shriraj Hegde
  • 829
  • 5
  • 18
  • 3
    This is probably a good solution and has worked for me some times before. I feel like this might be something that should be reported to the `matplotlib` team to ensure that this is listed in the `requirements.txt` for Fedora 35. It would be really annoying to have to run that command every time in every new environment you install `matplotlib` to. – Mahyar Mirrashed Jul 22 '22 at 02:13
  • @MahyarMirrashed I agree, but I am not sure how to approach the reporting. Because, as I understand, anaconda packages various projects by itself. – Shriraj Hegde Jul 23 '22 at 14:26
  • 2
    This solved the problem for me. I was having trouble installing vtk in Ubuntu 22.04 inside of a new conda environment. – Connor Ferster Dec 13 '22 at 00:03
  • 3
    This worked for me without having to try anything else. – Bryce Wayne Jan 02 '23 at 22:28
  • 1
    Works like a charm!! (tested on kali 2023.1). This solution is quite portable as the dependency can be added to the conda environment. Thus, it will work on my colleges' machines as well. – A.Casanova Apr 08 '23 at 19:03
  • 1
    Amazing answer ! This worked for me in fixing driver-ralated VTK seg-faults on Ubuntu 22.04 – Des Jun 11 '23 at 19:01
  • Thanks. It is good. – Peter Chen Aug 31 '23 at 16:55
11

Short answer: export LD_PRELOAD=/usr/lib64/libstdc++.so.6

Long answer:

The underlying problem is that we have a piece of software that was built with an older C++ compiler. Part of the compiler is its implementation of libstdc++ which becomes part of the runtime requirements for anything built by the compiler. The software in question has, evidently, brought its own, older implementation of libstdc++ along for the ride, and given its libstdc++ precedence over the system's libstdc++. Typically, this is done via the $LD_LIBRARY_PATH environment variable. Unfortunately, /usr/lib64/dri/swrast_dri.so is a piece of system software built by the native compiler for that system, and it's more recent than the compiler that built the other software in question. The result of this is that the older compiler's libstdc++ gets loaded first, with its older, more limited symbol set. When it then wants to load swrast, this fails because swrast insists on having the level of compiler/runtime with which it was built. The solution to this whole mess is the force the system's (newer) libstdc++ into use and prevent the older libstdc++ from being brought into play. This is achieved via the code snippet export LD_PRELOAD=/usr/lib64/libstdc++.so.6 where we set the preload environment variable.

Mahyar Mirrashed
  • 471
  • 1
  • 3
  • 14
  • 1
    This sounds like it circumvents the actual underlying issue. It sounds more like something is wrong with the conda installation and/or paths that should point to conda directories – FlyingTeller Feb 07 '22 at 13:05
  • 2
    @FlyingTeller, if you have suggestions, please feel free to answer the question. Otherwise, this was the best solution I could find comparing to the outrageous ones that others were suggesting online. – Mahyar Mirrashed Feb 07 '22 at 20:06
  • This did not work for me. I did `export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6` and am still seeing the error `libGL error: failed to load driver: iris` – Adam Aug 22 '23 at 14:40