Libtorch_cpu.so: undefined symbol

Megidd: <h1><a name="minimal-env-1" class="anchor" href="#minimal-env-1"></a>Minimal env</h1>
<p>Even a minimal Environment like below would throw similar errors:</p>
<pre data-code-wrap="bash"><code class="lang-bash">conda create -n minimal_pytorch python=3.6 pytorch torchvision torchaudio -c pytorch
source activate minimal_pytorch &amp;&amp; python -c "import torch; print(torch.__version__)"
</code></pre>
<p>A similar <code>undefined symbol</code> error is thrown:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "/usr/local/envs/minimal_pytorch/lib/python3.6/site-packages/torch/__init__.py", line 197, in &lt;module&gt;
    from torch._C import *  # noqa: F403
ImportError: /usr/local/envs/minimal_pytorch/lib/python3.6/site-packages/torch/lib/libtorch_cpu.so: undefined symbol: iJIT_NotifyEvent
</code></pre>
<h2><a name="python-version-2" class="anchor" href="#python-version-2"></a>Python version</h2>
<p>When Python version is omitted while creating the environment:</p>
<pre data-code-wrap="bash"><code class="lang-bash">conda create -n minimal_pytorch python pytorch torchvision torchaudio -c pytorch
</code></pre>
<p>The error is resolved:</p>
<pre><code class="lang-auto">source activate minimal_pytorch &amp;&amp; python -c "import torch; print(torch.__version__)"
</code></pre>
<p>PyTorch version is received without any error:</p>
<pre><code class="lang-auto">2.2.2
</code></pre>
<p>I’m kind of confused <img src="https://discuss.pytorch.org/images/emoji/apple/roll_eyes.png?v=12" title=":roll_eyes:" class="emoji" alt=":roll_eyes:" loading="lazy" width="20" height="20"></p>
<p>Eventually, I guess I have to use a Docker container as suggested here:</p>
<aside class="quote" data-post="4" data-topic="126640">
  <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/czotti/48/8031_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/undefined-symbol-pytorch-1-7-0-and-above/126640/4">Undefined symbol pytorch 1.7.0 and above</a> 
  </div>
  <blockquote>
    The only way I found to make it work is to use a docker container with the required PyTorch version in it.
  </blockquote>
</aside>


ptrblck: <p>The PyTorch binaries are not built for Python 3.6 anymore, so the first command should install a <code>torch&lt;=1.10.2</code> if I’m not mistaken.<br>
Use a newer Python version (3.8 - 3.12) and it should work.</p>

yrraadi-io: <p>I’m facing this issue with python 3.9.*, when installing pytorch via conda.</p>

Megidd: <p>Eventually, I solved the problem by resolving version mismatches. The exact commands are here:</p>
<aside class="onebox githubissue" data-onebox-src="https://github.com/conda/conda/issues/13812#issuecomment-2071445372">
  <header class="source">

      <a href="https://github.com/conda/conda/issues/13812#issuecomment-2071445372" target="_blank" rel="noopener nofollow ugc">github.com/conda/conda</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/conda/conda/issues/13812#issuecomment-2071445372" target="_blank" rel="noopener nofollow ugc">libtorch_cpu.so: undefined symbol</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2024-04-17" data-time="09:22:57" data-timezone="UTC">09:22AM - 17 Apr 24 UTC</span>
      </div>

        <div class="date">
          closed <span class="discourse-local-date" data-format="ll" data-date="2024-04-21" data-time="11:39:06" data-timezone="UTC">11:39AM - 21 Apr 24 UTC</span>
        </div>

      <div class="user">
        <a href="https://github.com/Megidd" target="_blank" rel="noopener nofollow ugc">
          <img alt="Megidd" src="https://avatars.githubusercontent.com/u/17475482?v=4" class="onebox-avatar-inline" width="20" height="20">
          Megidd
        </a>
      </div>
    </div>

    <div class="labels">
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          type::support
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          source::community
        </span>
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">### Checklist

- [X] I added a descriptive title
- [X] I searched open report<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">s and couldn't find a duplicate

### What happened?

# Minimal env

A minimal environment like below is created:

```bash
conda create -n minimal_pytorch python=3.6 pytorch torchvision torchaudio -c pytorch
```

Just getting the PyTorch version by the following command would throw errors:

```bash
source activate minimal_pytorch &amp;&amp; python -c "import torch; print(torch.__version__)"
```

This `undefined symbol` error is thrown:

```
Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "/usr/local/envs/minimal_pytorch/lib/python3.6/site-packages/torch/__init__.py", line 197, in &lt;module&gt;
    from torch._C import *  # noqa: F403
ImportError: /usr/local/envs/minimal_pytorch/lib/python3.6/site-packages/torch/lib/libtorch_cpu.so: undefined symbol: iJIT_NotifyEvent
```

## Python version

When Python version is omitted while creating the environment:

```bash
conda create -n minimal_pytorch python pytorch torchvision torchaudio -c pytorch
```

The error is resolved:

```
source activate minimal_pytorch &amp;&amp; python -c "import torch; print(torch.__version__)"
```

PyTorch version is received without any error:

```
2.2.2
```

## Note

I have posted a question here too: https://stackoverflow.com/q/78328401/3405291


### Conda Info

```shell
active environment : minimal_pytorch
    active env location : /usr/local/envs/minimal_pytorch
            shell level : 1
       user config file : /root/.condarc
 populated config files : /usr/local/.condarc
          conda version : 23.11.0
    conda-build version : not installed
         python version : 3.10.13.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=broadwell
                          __conda=23.11.0=0
                          __glibc=2.35=0
                          __linux=6.1.58=0
                          __unix=0=0
       base environment : /usr/local  (writable)
      conda av data dir : /usr/local/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /usr/local/pkgs
                          /root/.conda/pkgs
       envs directories : /usr/local/envs
                          /root/.conda/envs
               platform : linux-64
             user-agent : conda/23.11.0 requests/2.31.0 CPython/3.10.13 Linux/6.1.58+ ubuntu/22.04.3 glibc/2.35 solver/libmamba conda-libmamba-solver/23.12.0 libmambapy/1.5.5
                UID:GID : 0:0
             netrc file : None
           offline mode : False
```


### Conda Config

```shell
==&gt; /usr/local/.condarc &lt;==
channels:
  - conda-forge
always_yes: True
```


### Conda list

```shell
# packages in environment at /usr/local/envs/minimal_pytorch:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                  2_kmp_llvm    conda-forge
blas                      2.122                       mkl    conda-forge
blas-devel                3.9.0            22_linux64_mkl    conda-forge
bzip2                     1.0.8                hd590300_5    conda-forge
ca-certificates           2024.2.2             hbcca054_0    conda-forge
cudatoolkit               11.3.1              hb98b00a_13    conda-forge
dataclasses               0.8                pyh787bdff_2    conda-forge
ffmpeg                    4.3                  hf484d3e_0    pytorch
freetype                  2.12.1               h267a509_2    conda-forge
gmp                       6.3.0                h59595ed_1    conda-forge
gnutls                    3.6.13               h85f3911_1    conda-forge
icu                       73.2                 h59595ed_0    conda-forge
jpeg                      9e                   h0b41bf4_3    conda-forge
lame                      3.100             h166bdaf_1003    conda-forge
lcms2                     2.12                 hddcbb42_0    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
lerc                      3.0                  h9c3ff4c_0    conda-forge
libblas                   3.9.0            22_linux64_mkl    conda-forge
libcblas                  3.9.0            22_linux64_mkl    conda-forge
libdeflate                1.10                 h7f98852_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 13.2.0               h807b86a_5    conda-forge
libgfortran-ng            13.2.0               h69a702a_5    conda-forge
libgfortran5              13.2.0               ha4646dd_5    conda-forge
libhwloc                  2.10.0          default_h2fb2949_1000    conda-forge
libiconv                  1.17                 hd590300_2    conda-forge
liblapack                 3.9.0            22_linux64_mkl    conda-forge
liblapacke                3.9.0            22_linux64_mkl    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libpng                    1.6.43               h2797004_0    conda-forge
libsqlite                 3.45.2               h2797004_0    conda-forge
libstdcxx-ng              13.2.0               h7e041cc_5    conda-forge
libtiff                   4.3.0                h0fcbabc_4    conda-forge
libuv                     1.48.0               hd590300_0    conda-forge
libwebp-base              1.4.0                hd590300_0    conda-forge
libxml2                   2.12.6               h232c23b_2    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
llvm-openmp               18.1.3               h4dfa4b3_0    conda-forge
mkl                       2024.1.0           ha957f24_692    conda-forge
mkl-devel                 2024.1.0           ha770c72_692    conda-forge
mkl-include               2024.1.0           ha957f24_692    conda-forge
ncurses                   6.4.20240210         h59595ed_0    conda-forge
nettle                    3.6                  he412f7d_0    conda-forge
numpy                     1.19.5           py36hfc0c790_2    conda-forge
olefile                   0.46               pyh9f0ad1d_1    conda-forge
openh264                  2.1.1                h780b84a_0    conda-forge
openjpeg                  2.5.0                h7d73246_0    conda-forge
openssl                   1.1.1w               hd590300_0    conda-forge
pillow                    8.3.2            py36h676a545_0    conda-forge
pip                       21.3.1             pyhd8ed1ab_0    conda-forge
python                    3.6.15          hb7a2778_0_cpython    conda-forge
python_abi                3.6                     2_cp36m    conda-forge
pytorch                   1.10.2          py3.6_cuda11.3_cudnn8.2.0_0    pytorch
pytorch-mutex             1.0                        cuda    pytorch
readline                  8.2                  h8228510_1    conda-forge
setuptools                58.0.4           py36h5fab9bb_2    conda-forge
sqlite                    3.45.2               h2c6b66d_0    conda-forge
tbb                       2021.12.0            h00ab1b0_0    conda-forge
tk                        8.6.13          noxft_h4845f30_101    conda-forge
torchaudio                0.10.2               py36_cu113    pytorch
torchvision               0.11.3               py36_cu113    pytorch
typing_extensions         4.1.1              pyha770c72_0    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
zlib                      1.2.13               hd590300_5    conda-forge
zstd                      1.5.5                hfc55251_0    conda-forge
```


### Additional Context

_No response_</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>