0

I want to use sentence-transformers. To do this, I installed sentence-transformers as follows:

pip install sentence-transformers

Then, I did my import as follows:

from sentence_transformers import SentenceTransformer

Which resulted in the following error:

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

The entire Traceback is:

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

I have tried upgrading Numpy:

pip install numpy --upgrade

But this returns:

Requirement already up-to-date: numpy in c:\...\site-packages (1.22.2)

What goes wrong here? And how can I overcome this error?

4

0 回答 0