gpt4 book ai didi

python-3.x - 运行时错误 : module compiled against API version 0xe but this version of numpy is 0xd when importing sentence-transformers

转载 作者:行者123 更新时间:2023-12-05 05:45:33 25 4
gpt4 key购买 nike

我想使用句子转换器。为此,我按如下方式安装了句子转换器:

pip install sentence-transformers

然后,我按如下方式进行导入:

从 sentence_transformers 导入 SentenceTransformer

导致以下错误:

RuntimeError:针对 API 版本 0xe 编译的模块,但此版本的 numpy 是 0xd

整个回溯是:

Traceback (most recent call last):

File "<ipython-input-112-dbcd88385343>", line 1, in <module>
from sentence_transformers import SentenceTransformer

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\__init__.py", line 3, in <module>
from .datasets import SentencesDataset, ParallelSentencesDataset

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\datasets\__init__.py", line 3, in <module>
from .ParallelSentencesDataset import ParallelSentencesDataset

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\datasets\ParallelSentencesDataset.py", line 4, in <module>
from .. import SentenceTransformer

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\SentenceTransformer.py", line 27, in <module>
from .models import Transformer, Pooling, Dense

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\models\__init__.py", line 1, in <module>
from .Transformer import Transformer

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\sentence_transformers\models\Transformer.py", line 2, in <module>
from transformers import AutoModel, AutoTokenizer, AutoConfig

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1985, in __getattr__
value = getattr(module, name)

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1984, in __getattr__
module = self._get_module(self._class_to_module[name])

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1993, in _get_module
return importlib.import_module("." + module_name, self.__name__)

File "C:\Users\20200016\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\models\auto\modeling_auto.py", line 24, in <module>
from ..albert.modeling_albert import (

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\models\albert\modeling_albert.py", line 51, in <module>
from .configuration_albert import AlbertConfig

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\models\albert\configuration_albert.py", line 21, in <module>
from ...onnx import OnnxConfig

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\onnx\__init__.py", line 17, in <module>
from .convert import export, validate_model_outputs

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\onnx\convert.py", line 23, in <module>
from .. import PreTrainedModel, PreTrainedTokenizer, TensorType, TFPreTrainedModel, is_torch_available

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1984, in __getattr__
module = self._get_module(self._class_to_module[name])

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\file_utils.py", line 1993, in _get_module
return importlib.import_module("." + module_name, self.__name__)

File "C:\Users\20200016\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)

File "C:\Users\20200016\AppData\Roaming\Python\Python38\site-packages\transformers\modeling_tf_utils.py", line 27, in <module>
import tensorflow as tf

File "C:\Users\20200016\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 37, in <module>
from tensorflow.python.tools import module_util as _module_util

File "C:\Users\20200016\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 37, in <module>
from tensorflow.python.eager import context

File "C:\Users\20200016\Anaconda3\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
from tensorflow.python.client import pywrap_tf_session

File "C:\Users\20200016\Anaconda3\lib\site-packages\tensorflow\python\client\pywrap_tf_session.py", line 19, in <module>
from tensorflow.python.client._pywrap_tf_session import *

ImportError: SystemError: <built-in method __contains__ of dict object at 0x0000021655B72740> returned a result with an error set

我试过升级 Numpy:

pip install numpy --upgrade

但这会返回:

要求已经是最新的:c:\...\site-packages (1.22.2) 中的 numpy

这里出了什么问题?我该如何克服这个错误?

最佳答案

我有过类似的问题,在我的例子中升级 numpy 解决了它。我检查了 requirements.txt对于 sentencetransformer,但他们没有说明具体版本。

此外,您可以尝试安装没有依赖项 pip install --no-deps sentence-transformers 的 SentenceTransformer,然后手动安装它们。通过下载 requirements.txt 并通过 pip install -r requirements.txt 安装它。在此过程中,您还可以更轻松地查看是否与某些包存在任何冲突,例如,这些信息可能会帮助您确定需要哪个确切的 numpy 版本。

关于python-3.x - 运行时错误 : module compiled against API version 0xe but this version of numpy is 0xd when importing sentence-transformers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71339595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com