导入torchtext时遇OSError:libc10.dylib中缺失符号
导入torchtext时遭遇libc10.dylib缺失符号的OSError问题
报错详情
执行Python脚本导入torchtext时触发以下OSError:
--------------------------------------------------------------------------- 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/python@3.12/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
运行环境
- 系统:macOS 14.6.1
- 环境管理:Poetry创建虚拟环境
- 初始依赖配置:
- python = "^3.11"
- torch = "^2.4.0"
- torchtext = "^0.18.0"
已尝试的解决方法
尝试过多组torch与torchtext版本组合更新,均未解决问题:
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
此外,尝试使用Conda创建独立环境,问题仍然存在,且未找到有效的论坛解决方案。
内容的提问来源于stack exchange,提问作者mattiazza
相关产品推荐
相关产品推荐

