我尝试在 Python 脚本中导入
torchtext
,但遇到与 libc10.dylib
中缺少符号相关的错误。当我运行脚本时,出现以下错误:
---------------------------------------------------------------------------
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
我正在 macOS 14.6.1 中工作,我使用具有以下依赖项的诗歌设置了虚拟环境 (venv)
我已经尝试更改 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 创建一个环境,但最终得到了相同的结果。我也没有找到任何有帮助的论坛。
同样的问题! 环境完整
正在收集环境信息...PyTorch版本:2.4.0 正在调试 构建:错误 CUDA 用于构建 PyTorch:无 ROCM 用于构建 PyTorch:不适用
操作系统:macOS 14.5(arm64)GCC版本:无法收集Clang版本: 15.0.0 (clang-1500.1.0.2.5) CMake 版本:无法收集 Libc 版本:N/A
Python版本:3.11.9(主要,2024年4月19日,11:43:47)[Clang 14.0.6] (64位运行时)Python平台:macOS-14.5-arm64-arm-64bit 是CUDA 可用:错误 CUDA 运行时版本:未设置 CUDA CUDA_MODULE_LOADING 至: N/A GPU 型号和配置: 无 CUDA Nvidia 驱动程序版本: 无 CUDA cuDNN 版本:无 CUDA HIP 运行时版本:不适用 MIOpen 运行时 版本:N/A XNNPACK 是否可用:True
CPU:苹果M1 Pro
相关库的版本:[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] 火炬 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