8

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user8270077
  • 4,621
  • 17
  • 75
  • 140

3 Answers3

7

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

igrinis
  • 12,398
  • 20
  • 45
  • To be precise, the first pipeline popped up in 2.3, but IIRC a stable release was from version 2.5 onwards. – dennlinger May 20 '20 at 12:59
5

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

msklc
  • 553
  • 1
  • 8
  • 10
0

this worked for me: pip install transformers==4.11.3 run this command in cmd ref: https://github.com/huggingface/transformers/issues/10277