PyTorch Cannot Open libstdc++.so.6

If I import torch from python 3.8.0, I get the following error:

OSError: libstdc++.so.6: cannot open shared object file: No such file or directory



The strangest thing about it, however, is that I do have that shared object file and I can even grab it using ctypes.CDLL("libstdc++.so.6", mode=ctypes.RTLD_GLOBAL) exactly as pytorch tries and fails to do! After doing so, torch imports fine! What is going on, and how can I avoid having to put the ctypes.CDLL call before everytime I import torch in every file I use torch in?

Thanks,
Jack

Upon further inspection, it seems like pytorch doesn’t directly include libstdc++.so.6, but rather includes libtorch_global_deps.so.

Why can I find libstdc++.so.6 directly, but not when importing libtorch_global_deps.so?

Thanks,
Jack

I fixed this temporarily by exporting LD_LIBRARY_PATH=/usr/lib64, but it’s strange because I could use ctypes.CDLL to import “libstdc++.so.6” directly without doing this…idk