huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
132.13k stars 26.33k forks source link

Cannot import pipelines from transformers #18664

Closed balachander1964 closed 1 year ago

balachander1964 commented 2 years ago

Hi, I use a Windows 10 Proffessional laptop for development and am using python 3.7.6 conda virtual env. I get the following run time error when running my code (below, after the error details). << bertqa interactive window [PTVS 17.0.22089.1-17.0] Type $help for a list of commands. The interactive window has not yet started. Running D:\Projects2017\bertqa\bertqa\aaa_scratch.py Traceback (most recent call last): File "d:\python\Anaconda3\envs\transformers_qa\lib\site-packages\transformers\utils\import_utils.py", line 905, in _get_module return importlib.import_module("." + module_name, self.name) File "d:\python\Anaconda3\envs\transformers_qa\lib\importlib__init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked File "", line 728, in exec_module File "", line 219, in _call_with_frames_removed File "d:\python\Anaconda3\envs\transformers_qa\lib\site-packages\transformers\pipelines\init__.py", line 50, in from .image_classification import ImageClassificationPipeline File "d:\python\Anaconda3\envs\transformers_qa\lib\site-packages\transformers\pipelines\image_classification.py", line 15, in from PIL import Image File "d:\python\Anaconda3\envs\transformers_qa\lib\site-packages\PIL\Image.py", line 69, in from . import _imaging as core ImportError: DLL load failed: The specified module could not be found.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "D:\Projects2017\bertqa\bertqa\aaa_scratch.py", line 5, in from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipelines File "", line 1032, in _handle_fromlist File "d:\python\Anaconda3\envs\transformers_qa\lib\site-packages\transformers\utils\import_utils.py", line 893, in getattr value = self._get_module(name) File "d:\python\Anaconda3\envs\transformers_qa\lib\site-packages\transformers\utils\import_utils.py", line 910, in _get_module ) from e RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback): DLL load failed: The specified module could not be found.

The following is the code I am trying to execute: <<

imports

import os, sys import pandas as PD import numpy as NP from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipelines

_text = 'I bought a Toyota Corala last January. It works well..' _questions = [ 'What did the person buy?', 'What is working?', 'When did he buy?', ]

_model_name = "deepset/tinyroberta-squad2"

def main(): '''Main entry point''' nlp = pipeline('question-answering', model=model_name, tokenizer=model_name) qa_input = {} qa_input['question'] = _questions[0] qa_input['context'] = _text

answer = nlp(QA_input) print(answer)

''' Required for all python programs. ''' if name == 'main': print('Starting the QA tool.') main() print('Done')

I will appreciate if you let me know how to overcome this issue. Awaiting your reply.

gante commented 2 years ago

Hi @balachander1964 -- if you check the error log you shared, the error does not come from the transformers library. From a quick google search, the error seems to be from the environment set up (try googling DLL load failed: The specified module could not be found.)

As per our issues guidelines, we reserve GitHub issues for bugs in the repository and/or feature requests. For any other matters, we'd like to invite you to use our forum 🤗

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.