mattiazza
mattiazza

Reputation: 21

`AttributeError` when importing `torchtext` - "Symbol not found in libc10.dylib"

I'm trying to import torchtext in my Python script, but I'm encountering an error related to a missing symbol in libc10.dylib. When I run my script, I get the following error:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[4], line 7
      5 import torch.nn.functional as F
      6 from torchinfo import summary
----> 7 from torchtext.datasets import IMDB
      8 from torch.utils.data import DataLoader, Dataset, random_split
      9 from torchtext.data.utils import get_tokenizer

File ~/.venv/lib/python3.12/site-packages/torchtext/__init__.py:18
     15     _WARN = False
     17 # the following import has to happen first in order to load the torchtext C++ library
---> 18 from torchtext import _extension  # noqa: F401
     20 _TEXT_BUCKET = "https://download.pytorch.org/models/text/"
     22 _CACHE_DIR = os.path.expanduser(os.path.join(_get_torch_home(), "text"))

File ~/.venv/lib/python3.12/site-packages/torchtext/_extension.py:64
     59     # This import is for initializing the methods registered via PyBind11
     60     # This has to happen after the base library is loaded
     61     from torchtext import _torchtext  # noqa
---> 64 _init_extension()

File ~/.venv/lib/python3.12/site-packages/torchtext/_extension.py:58, in _init_extension()
     55 if not _mod_utils.is_module_available("torchtext._torchtext"):
     56     raise ImportError("torchtext C++ Extension is not found.")
---> 58 _load_lib("libtorchtext")
     59 # This import is for initializing the methods registered via PyBind11
     60 # This has to happen after the base library is loaded
     61 from torchtext import _torchtext

File ~/.venv/lib/python3.12/site-packages/torchtext/_extension.py:50, in _load_lib(lib)
     48 if not path.exists():
     49     return False
---> 50 torch.ops.load_library(path)
     51 return True

File ~/.venv/lib/python3.12/site-packages/torch/_ops.py:1295, in _Ops.load_library(self, path)
   1290 path = _utils_internal.resolve_library_path(path)
   1291 with dl_open_guard():
   1292     # Import the shared library into the process, thus running its
   1293     # static (global) initialization code in order to register custom
   1294     # operators with the JIT.
-> 1295     ctypes.CDLL(path)
   1296 self.loaded_libraries.add(path)

File /opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py:379, in CDLL.__init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    376 self._FuncPtr = _FuncPtr
    378 if handle is None:
--> 379     self._handle = _dlopen(self._name, mode)
    380 else:
    381     self._handle = handle

OSError: dlopen(/.venv/lib/python3.12/site-packages/torchtext/lib/libtorchtext.so, 0x0006): Symbol not found: __ZN3c105ErrorC1ENSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES7_PKv
  Referenced from: <7E3C8144-0701-3505-8587-6E953627B6AF> /.venv/lib/python3.12/site-packages/torchtext/lib/libtorchtext.so
  Expected in:     <69A84A04-EB16-3227-9FED-383D2FE98E93> /3.venv/lib/python3.12/site-packages/torch/lib/libc10.dylib

I'm working in macOS 14.6.1 and I set up my virtual environment (venv) using poetry with the following dependencies

I've already tried to change the versions of torch and torchtext without any success

poetry update torch==2.3.0 torchtext==0.18
poetry update torch==2.0.1 torchtext==0.15.1
poetry update torch==2.2.1 torchtext==0.17.2 python==3.9 
poetry update torch==2.2.2 torchtext==0.17.2

I've also tried to create an environment using conda, but I end up with the same result. I haven't found any forum that says anything helpful either.

Upvotes: 2

Views: 660

Answers (2)

rikb
rikb

Reputation: 572

Version mismatch problem:

pip uninstall torch
pip uninstall torchtext
pip install torch==2.3.0
pip install torchtext==0.18

https://discuss.pytorch.org/t/unable-to-import-torchtext-from-torchtext-datasets-import-imdb-from-torchtext-vocab-import-vocab/207843/3

Upvotes: 1

rikb
rikb

Reputation: 572

same issue with python 3.11! full environment

Collecting environment information... PyTorch version: 2.4.0 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: macOS 14.5 (arm64) GCC version: Could not collect Clang version: 15.0.0 (clang-1500.1.0.2.5) CMake version: Could not collect Libc version: N/A

Python version: 3.11.9 (main, Apr 19 2024, 11:43:47) [Clang 14.0.6 ] (64-bit runtime) Python platform: macOS-14.5-arm64-arm-64bit Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Apple M1 Pro

Versions of relevant libraries: [pip3] numpy==1.26.4 [pip3] torch==2.4.0 [pip3] torchdata==0.8.0 [pip3] torchtext==0.18.0 [pip3] torchvision==0.19.0 [conda] numpy 1.26.4
pypi_0 pypi [conda] torch 2.4.0
pypi_0 pypi [conda] torchdata 0.8.0
pypi_0 pypi [conda] torchtext 0.18.0
pypi_0 pypi [conda] torchvision 0.19.0

Upvotes: 0

Related Questions