Cannot import torchtext (libtorchtext.so: undefined symbol)

vdw: <p>After installing <code>torchext</code>, I get the following error when trying to import anything from it</p>
<pre><code class="lang-auto">OSError: &lt;path&gt;/anaconda3/envs/py311/lib/python3.11/site-packages/torchtext/lib/libtorchtext.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
</code></pre>
<p>According this this <a href="https://github.com/pytorch/text/issues/1342" rel="noopener nofollow ugc">report</a>, it could be a compatibility issues. So have check the requirements <a href="https://github.com/pytorch/text#installation" rel="noopener nofollow ugc">here</a>, which seem to match my installation when checking with <code>conda list</code>:</p>
<pre><code class="lang-auto">...
pytorch                   2.3.0           py3.11_cuda11.8_cudnn8.7.0_0    pytorch
...
torchtext                 0.18.0                    py311    pytorch
...
</code></pre>
<p>Not sure how to approach this issue further. Everything I found online was referring to problems due to mismatching versions.</p>

ptrblck: <p>Yes, these issues are indeed usually caused by mismatched versions. Just to confirm before I try to reproduce it: are you seeing this error while simply importing <code>torchtext</code>?</p>

vdw: <p>I’ve just checked again, and now it seems working. So odd, I still have the screenshot from the error and I didn’t change anything after that. Not sure where I misses something, maybe I did not restart the kernel in Jupyter appropriately.</p>
<p>In any case, now I get the warning</p>
<blockquote>
<p>Torchtext is deprecated and the last released version will be 0.18 (this one)</p>
</blockquote>
<p>so there’s no use to stick with it anymore. Probably old news, but I rarely find some time to code anything myself, so I’ve never noticed.</p>

kyoungbinkim: <p>I have same issue</p>
<p>versions;<br>
torch==2.7.0.dev20250217+cu126<br>
torchtext==0.18.0</p>
<pre><code class="lang-auto">&gt;&gt;&gt; import torch
&gt;&gt;&gt; import torchtext
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/home/web3-2/workspace/DeLAP/demo/pytorch/finetuning/llama3.2/.venv/lib/python3.10/site-packages/torchtext/__init__.py", line 18, in &lt;module&gt;
    from torchtext import _extension  # noqa: F401
  File "/home/web3-2/workspace/DeLAP/demo/pytorch/finetuning/llama3.2/.venv/lib/python3.10/site-packages/torchtext/_extension.py", line 64, in &lt;module&gt;
    _init_extension()
  File "/home/web3-2/workspace/DeLAP/demo/pytorch/finetuning/llama3.2/.venv/lib/python3.10/site-packages/torchtext/_extension.py", line 58, in _init_extension
    _load_lib("libtorchtext")
  File "/home/web3-2/workspace/DeLAP/demo/pytorch/finetuning/llama3.2/.venv/lib/python3.10/site-packages/torchtext/_extension.py", line 50, in _load_lib
    torch.ops.load_library(path)
  File "/home/web3-2/workspace/DeLAP/demo/pytorch/finetuning/llama3.2/.venv/lib/python3.10/site-packages/torch/_ops.py", line 1390, in load_library
    ctypes.CDLL(path)
  File "/usr/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/web3-2/workspace/DeLAP/demo/pytorch/finetuning/llama3.2/.venv/lib/python3.10/site-packages/torchtext/lib/libtorchtext.so: undefined symbol: _ZN5torch6detail10class_baseC2ERKSsS3_SsRKSt9type_infoS6_

</code></pre>