Can not import pipeline from transformers

10,477

Solution 1

Check transformers version. Make sure you are on latest. Pipelines were introduced quite recently, you may have older version.

Solution 2

It is announced at the end of May that spacy-transformers v0.6.0 is compatible with the transformers v2.5.0. So, if you planning to use spacy-transformers also, it will be better to use v2.5.0 for transformers instead of the latest version.

So, try;

pip install transformers==2.5.0

pip install spacy-transformers==0.6.0

and use 2 pre-trained models same time without any problem

Share:
10,477
user8270077
Author by

user8270077

Updated on June 13, 2022

Comments

  • user8270077
    user8270077 about 2 years

    I have installed pytorch with conda and transformers with pip.

    I can import transformers without a problem but when I try to import pipeline from transformers I get an exception:

    from transformers import pipeline
    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    <ipython-input-4-69a9fd07ccac> in <module>
    ----> 1 from transformers import pipeline
    
    ImportError: cannot import name 'pipeline' from 'transformers' (C:\Users\Alienware\Anaconda3\envs\tf2\lib\site-packages\transformers\__init__.py)
    

    This is a view of the directory where it searches for the init.py file:

    enter image description here

    What is causing the problem and how can I resolve it?