haystack icon indicating copy to clipboard operation
haystack copied to clipboard

ImportError: cannot import name 'Document' from 'haystack'

Open mwunderlich opened this issue 2 years ago • 3 comments

Describe the bug I am getting the following issue with Python 3.11.4 and haystack 1.19.0 (fresh install in Conda environment on Macbook M1 with Ventura)

File ~/anaconda3/envs/transformers_new/lib/python3.11/site-packages/haystack/nodes/answer_generator/openai.py:5 2 import os 3 from typing import List, Optional, Tuple, Union ----> 5 from haystack import Document 6 from haystack.environment import HAYSTACK_REMOTE_API_TIMEOUT_SEC 7 from haystack.nodes.answer_generator import BaseGenerator

ImportError: cannot import name 'Document' from 'haystack'

Error message ImportError: cannot import name 'Document' from 'haystack'

Expected behavior Import should work.

Additional context Same issue has already been report here, but was closed: https://github.com/deepset-ai/haystack/issues/499

To Reproduce Try to import: from haystack.document_stores.elasticsearch import ElasticsearchDocumentStore

FAQ Check

System:

  • OS: Mac Os Ventura
  • GPU/CPU: M1
  • Haystack version (commit or version number): 1.19.0
  • DocumentStore:
  • Reader:
  • Retriever:

mwunderlich avatar Jul 30 '23 10:07 mwunderlich

I have been able to fix this by changing the import in haystack/nodes/answer_generator/openai.py. line 5 changed from: from haystack import Document to from haystack.schema import Document

This leads to the next error:

File ~/anaconda3/envs/transformers_new/lib/python3.11/site-packages/haystack/environment.py:8
      5 import sys
      6 from typing import Any, Dict, Optional
----> 8 from haystack import __version__
      9 from haystack.lazy_imports import LazyImport
     11 with LazyImport(message="Run 'pip install farm-haystack[inference]'") as torch_import:

ImportError: cannot import name '__version__' from 'haystack' (/Users/martinwunderlich/anaconda3/envs/transformers_new/lib/python3.11/site-packages/haystack/__init__.py)

mwunderlich avatar Jul 30 '23 10:07 mwunderlich

Hey, @mwunderlich... sorry for the late response!

Have you been able to get Haystack working?

anakin87 avatar Aug 09 '23 17:08 anakin87

Like this tutorial, below code works for me.

%%bash

pip install --upgrade pip
pip install farm-haystack[colab,preprocessing,elasticsearch,inference]

Note:

  • farm-haystack is 1.20.1
  • Before re-install pip package, I restarted Colab runtime.

xhiroga avatar Sep 24 '23 04:09 xhiroga