Undefined symbol pytorch 1.7.0 and above

czotti: <p>I was working with PyTorch 1.5.0 for quite some time and decided to update to 1.9.0.</p>
<p>System: Ubuntu 18.04<br>
Kernel: 4.15.0-147-generic <span class="hashtag">#151-Ubuntu</span> SMP<br>
I use pyenv 2.0.3 to manage virtual environment and python versions.<br>
I use python 3.7.9 installed with pyenv.</p>
<p>Make a new virtual environment with pyenv called XXXX.</p>
<p>My pip env shows</p>
<pre><code class="lang-auto">$ pip --version
pip 20.1.1 from /home/clement/.pyenv/versions/3.7.9/envs/XXXX/lib/python3.7/site-packages/pip (python 3.7)
$ pip uninstall torch torchvision torchaudio
WARNING: Skipping torch as it is not installed.
WARNING: Skipping torchvision as it is not installed.
WARNING: Skipping torchaudio as it is not installed.
$ python3 -c "import torch; torch.__version__"
Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
ModuleNotFoundError: No module named 'torch'
</code></pre>
<p>Everything is clean with the new setup.<br>
Now install PyTorch 1.9.0 everything goes well no error message from pip</p>
<pre><code class="lang-auto">pip3 install torch==1.9.0+cpu torchvision==0.10.0+cpu torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
</code></pre>
<p>So everything looks fine but</p>
<pre><code class="lang-auto">$ python3 -c "import torch; torch.__version__"
Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "/home/clement/.pyenv/versions/3.7.9/envs/XXXX/lib/python3.7/site-packages/torch/__init__.py", line 197, in &lt;module&gt;
    from torch._C import *  # noqa: F403
ImportError: /home/clement/.pyenv/versions/3.7.9/envs/XXXX/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so: undefined symbol: _ZN3c1019UndefinedTensorImpl10_singletonE
</code></pre>
<p>I found that any version above 1.7.0 (included) give me this kind of error message.</p>
<ul>
<li>1.7.0+cpu: _ZTIN3c1010TensorImplE</li>
<li>1.7.1+cpu: _ZTIN3c1010TensorImplE</li>
<li>1.8.0+cpu: _ZTIN3c1010TensorImplE</li>
<li>1.9.0+cpu: _ZN3c1019UndefinedTensorImpl10_singletonE</li>
</ul>
<p>I also tried the “normal” version <code>pip install torch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0</code></p>
<ul>
<li>1.7.0: _ZN3c107Warning4warnENS_14SourceLocationERKSsb<br>
I don’t have any compatible GPU so maybe the above error is as expected?</li>
</ul>
<p>I also tried with the python 3.6.9 from the ubuntu 18.04 repository I have the same behavior as above.</p>
<p>Furthermore, I tried to clean anything on my system that contains <code>find / -iname *torch*</code>.</p>
<p>Honestly I don’t know where to look for this issue. Any version prior to 1.7.0 install and works without any issues.<br>
I use docker with Ubuntu 18.04, and I could install 1.7.1 and works with torch. I think this come from my workstation, but I have no clues. If someone knows where I can start to look at.</p>

ptrblck: <p>Usually you would get this error message if you are trying to <code>import</code> custom extensions before importing PyTorch, which doesn’t seem to be the case here.<br>
I also assume that you don’t have any files, which could cause conflicts, in the current working directory.<br>
In that case, could you create a new virtual environment, install PyTorch there, and test it again?</p>

czotti: <p>No directory/file was named torch on my working folder, if it was the case I assume that torch==1.6.0 will also fail no ?</p>
<p>Here are the steps I have done for the new venv:</p>
<pre><code class="lang-auto">$ mkdir new_venv
$ cd new_venv
$ virtualenv -p python3 pytorch_test
Running virtualenv with interpreter /home/clement/.pyenv/shims/python3
Using base prefix '/usr'
New python executable in /home/clement/new_env/pytorch_test/bin/python3
Also creating executable in /home/clement/new_env/pytorch_test/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
$ source pytorch_test/bin/activate
(pytorch_test) $ where python3
/home/clement/new_env/pytorch_test/bin/python3
/usr/bin/python3
(pytorch_test) $ pip freeze
pkg-resources==0.0.0
(pytorch_test) $ pip install torch==1.7.0+cpu torchvision==0.8.0 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
(pytorch_test) $ python3 -c "import torch; print(torch.__version__)"
Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "/home/clement/new_env/pytorch_test/lib/python3.6/site-packages/torch/__init__.py", line 190, in &lt;module&gt;
    from torch._C import *
ImportError: /home/clement/new_env/pytorch_test/lib/python3.6/site-packages/torch/lib/libtorch_cpu.so: undefined symbol: _ZTIN3c1010TensorImplE
(pytorch_test) $ pip uninstall torch torchvision torchaudio
(pytorch_test) $ 
(pytorch_test) $ pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
(pytorch_test) $ python3 -c "import torch; print(torch.__version__)"
1.6.0+cpu
</code></pre>

czotti: <p>The only way I found to make it work is to use a docker container with the required PyTorch version in it.</p>