UKPLab / sentence-transformers

State-of-the-Art Text Embeddings
https://www.sbert.net
Apache License 2.0
15.46k stars 2.5k forks source link

improt error: ModuleNotFoundError: No module named 'torch._C' #1758

Open whitedogedev opened 2 years ago

whitedogedev commented 2 years ago

`In [1]: from sentence_transformers import SentenceTransformer

ModuleNotFoundError Traceback (most recent call last)

in ----> 1 from sentence_transformers import SentenceTransformer ~/anaconda3/envs/zhangxuewen/lib/python3.6/site-packages/sentence_transformers/__init__.py in 1 __version__ = "2.2.2" 2 __MODEL_HUB_ORGANIZATION__ = 'sentence-transformers' ----> 3 from .datasets import SentencesDataset, ParallelSentencesDataset 4 from .LoggingHandler import LoggingHandler 5 from .SentenceTransformer import SentenceTransformer ~/anaconda3/envs/zhangxuewen/lib/python3.6/site-packages/sentence_transformers/datasets/__init__.py in ----> 1 from .DenoisingAutoEncoderDataset import DenoisingAutoEncoderDataset 2 from .NoDuplicatesDataLoader import NoDuplicatesDataLoader 3 from .ParallelSentencesDataset import ParallelSentencesDataset 4 from .SentencesDataset import SentencesDataset 5 from .SentenceLabelDataset import SentenceLabelDataset ~/anaconda3/envs/zhangxuewen/lib/python3.6/site-packages/sentence_transformers/datasets/DenoisingAutoEncoderDataset.py in ----> 1 from torch.utils.data import Dataset 2 from typing import List 3 from ..readers.InputExample import InputExample 4 import numpy as np 5 import nltk ~/anaconda3/envs/zhangxuewen/lib/python3.6/site-packages/torch/utils/__init__.py in 2 import sys 3 ----> 4 from .throughput_benchmark import ThroughputBenchmark 5 from ._crash_handler import enable_minidumps, disable_minidumps, enable_minidumps_on_exceptions 6 ~/anaconda3/envs/zhangxuewen/lib/python3.6/site-packages/torch/utils/throughput_benchmark.py in 1 ----> 2 import torch._C 3 4 def format_time(time_us=None, time_ms=None, time_s=None): 5 '''Defines how to format time''' ModuleNotFoundError: No module named 'torch._C'`
whitedogedev commented 2 years ago

import sklearn can solve this question

SebJansen commented 1 year ago

I tried with python3.11, but there where wheels missing on pypi

then on 3.10, I got the aforementioned error message which you copy pasted

eventually with 3.9, I got things working

my 2c, caveat emptor

kevin-wijaya commented 5 months ago

I downgraded the transformers library to version 4.30.2 and installed sentencepiece If there’s still an issue and it seems related to the numpy version, then downgrade numpy to version 1.26.4 This worked for me