Search code examples
pythonpython-3.xpipelinehuggingface-transformersanaconda3

Can not import pipeline from transformers


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?


Solution

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