Can't import in Python 3

Albert_Christianto: <p>Hello, is anyone have a solution for this issue?</p>
<p>Traceback (most recent call last):<br>
File “”, line 1, in <br>
File “/usr/local/lib/python3.5/dist-packages/torch/<strong>init</strong>.py”, line 80, in <br>
from torch._C import *<br>
ImportError: /usr/local/lib/python3.5/dist-packages/torch/lib/libshm.so: undefined symbol: _ZTI24THRefcountedMapAllocator</p>
<p>I have tried to reinstall pytorch several times, but it doesn’t work.</p>

ptrblck: <p>How did you install PyTorch?<br>
Did you use conda, pip or built from source?</p>

Albert_Christianto: <p>I use pip3 to install pytorch.</p>

ptrblck: <p>Could you run</p>
<pre><code class="lang-auto">pip uinstall torch
</code></pre>
<p>a few times?<br>
Probably there is an older version of <code>libshm.so</code> somewhere.</p>

Albert_Christianto: <p>Have tried that, but the second try, it said torch isn’t installed so there is no need to uninstall.</p>

ptrblck: <p>Are you using virtual environments?<br>
Could there be somehow another PyTorch installation?</p>

Ranahanocka: <aside class="quote no-group" data-username="ptrblck" data-post="4" data-topic="24041">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>libshm.so</p>
</blockquote>
</aside>
<p>maybe try looking for any places that this may exist:</p>
<blockquote>
<p>sudo find / -name “libshm.so”</p>
</blockquote>
<p>and delete any folders with torch.</p>
<p>Another option is to create a virtual env with conda. It works well. <a href="https://dziganto.github.io/data%20science/python/anaconda/Creating-Conda-Environments/" rel="noopener nofollow ugc">Here</a> is a good guide. But basically, it’s three commands (after installing conda of course) - assuming you wanted python 3.6 and cuda 8:</p>
<blockquote>
<p>conda create -n pytorch python=3.6<br>
source activate pytorch<br>
conda install pytorch torchvision cuda80 -c pytorch</p>
</blockquote>
<p>and b/c it’s a virtual env it should not care about previous installations (in theory of course <img src="https://discuss.pytorch.org/images/emoji/apple/laughing.png?v=12" title=":laughing:" class="emoji" alt=":laughing:" loading="lazy" width="20" height="20">)</p>

Albert_Christianto: <p>For your information, I use default python3 from ubuntu and I try to avoid install anaconda because it will crash my other program (library installation and environment, need more time to adjust the library in anaconda python)<br>
So based on your answer, the error is caused by last installation pytorch ?</p>

nnwnh: <p>Hi, I am having the similar error. I could import torch. Can someone help me identify the problem?</p>
<p>I tried a few, uninstalling and installing pip install torch. - doesnt work.<br>
I tried , pip install torch==1.7.0+cpu torchvision==0.8.1+cpu -f <a href="https://download.pytorch.org/whl/torch_stable.html" rel="noopener nofollow ugc">https://download.pytorch.org/whl/torch_stable.html</a></p>
<p>The Error:</p>
<pre><code>import torch
</code></pre>
<p>File “/home/…/lib/python3.8/site-packages/torch/<strong>init</strong>.py”, line 190, in <br>
from torch._C import *<br>
ImportError: /home/…/lib/python3.8/site-packages/torch/lib/libshm.so: undefined symbol: _ZTI24THRefcountedMapAllocator</p>

ptrblck: <p>You might have conflicting packages currently installed to rerun <code>pip uninstall torch -y</code> a few times until all packages are uninstalled and reinstall the right one afterwards. Alternatively, create a new virtual environment and install PyTorch once there.</p>