PyTorch Cannot Open libstdc++.so.6

username: jackeown
cooked: <p>If I import torch from python 3.8.0, I get the following error:</p>
<blockquote>
<p>OSError: libstdc++.so.6: cannot open shared object file: No such file or directory</p>
</blockquote>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/b/3bb2c0585bdb52589341eb16f8f7d9c9b637f9f3.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/3bb2c0585bdb52589341eb16f8f7d9c9b637f9f3" title="1"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/b/3bb2c0585bdb52589341eb16f8f7d9c9b637f9f3_2_690x388.jpeg" alt="1" data-base62-sha1="8w78UAzoBybaI3u9CvzeTibR6yn" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/b/3bb2c0585bdb52589341eb16f8f7d9c9b637f9f3_2_690x388.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/3/b/3bb2c0585bdb52589341eb16f8f7d9c9b637f9f3_2_1035x582.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/3/b/3bb2c0585bdb52589341eb16f8f7d9c9b637f9f3_2_1380x776.jpeg 2x" data-dominant-color="1B1E2E"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">1</span><span class="informations">1920×1080 626 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p><br><br></p>
<p>The strangest thing about it, however, is that I <em>do</em> have that shared object file and I can even grab it using <code>ctypes.CDLL("libstdc++.so.6", mode=ctypes.RTLD_GLOBAL)</code> 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?</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/7/977b11bcd5c6be75621cbe7c170baad0810af472.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/977b11bcd5c6be75621cbe7c170baad0810af472" title="working"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/9/7/977b11bcd5c6be75621cbe7c170baad0810af472_2_690x388.jpeg" alt="working" data-base62-sha1="lC3LUwR0pMrY5NYW7QWnCfiTWcq" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/9/7/977b11bcd5c6be75621cbe7c170baad0810af472_2_690x388.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/9/7/977b11bcd5c6be75621cbe7c170baad0810af472_2_1035x582.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/9/7/977b11bcd5c6be75621cbe7c170baad0810af472_2_1380x776.jpeg 2x" data-dominant-color="1D2030"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">working</span><span class="informations">1920×1080 572 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Thanks,<br>
Jack</p>

username: jackeown
cooked: <p>Upon further inspection, it seems like pytorch doesn’t directly include <code>libstdc++.so.6</code>, but rather includes <code>libtorch_global_deps.so</code>.</p>
<p>Why can I find <code>libstdc++.so.6</code> directly, but not when importing <code>libtorch_global_deps.so</code>?</p>
<p>Thanks,<br>
Jack</p>

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