Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'default_from_dict' from 'haystack' #335

Closed
hyerzn opened this issue Feb 4, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@hyerzn
Copy link

hyerzn commented Feb 4, 2024

An error occurred while following your manual.
https://haystack.deepset.ai/integrations/elasticsearch-document-store#usage

from haystack_integrations.document_stores.elasticsearch import ElasticsearchDocumentStore

document_store = ElasticsearchDocumentStore(hosts = "http://localhost:9200")

and I got below error.

---------------------------------------------------------------------------
{
	"name": "ImportError",
	"message": "cannot import name 'default_from_dict' from 'haystack' (/Users/anaconda3/envs/venv/lib/python3.9/site-packages/haystack/__init__.py)",
	"stack": "---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[50], line 1
----> 1 from haystack_integrations.document_stores.elasticsearch import ElasticsearchDocumentStore
      3 document_store = ElasticsearchDocumentStore(hosts = \"http://localhost:9200\")

File ~/anaconda3/envs/venv/lib/python3.9/site-packages/haystack_integrations/document_stores/elasticsearch/__init__.py:4
      1 # SPDX-FileCopyrightText: 2023-present deepset GmbH <[email protected]>
      2 #
      3 # SPDX-License-Identifier: Apache-2.0
----> 4 from .document_store import ElasticsearchDocumentStore
      6 __all__ = [\"ElasticsearchDocumentStore\"]

File ~/anaconda3/envs/venv/lib/python3.9/site-packages/haystack_integrations/document_stores/elasticsearch/document_store.py:11
      9 # There are no import stubs for elastic_transport and elasticsearch so mypy fails
     10 from elastic_transport import NodeConfig  # type: ignore[import-not-found]
---> 11 from haystack import default_from_dict, default_to_dict
     12 from haystack.dataclasses import Document
     13 from haystack.document_stores.errors import DocumentStoreError, DuplicateDocumentError

ImportError: cannot import name 'default_from_dict' from 'haystack' (/Users/anaconda3/envs/venv/lib/python3.9/site-packages/haystack/__init__.py)"
}

Describe your environment (please complete the following information):

  • OS: MacOS
  • Haystack version: 2.0.0b5
  • Integration version: 0.2.0
@hyerzn hyerzn added the bug Something isn't working label Feb 4, 2024
@masci
Copy link
Contributor

masci commented Feb 4, 2024

(edit: was on mobile when I first answered, now elaborating a bit more)

This is most likely an installation problem. As you can see from the docs, the version 1.x and 2.x of Haystack cannot exist in the same environment: during the installation they overwrite each other causing those weird import errors. The quickest solution is to start with a fresh environment.

If that's not your case, another similar problem might be you did pip install haystack, that would install some other software. If that's the case:

pip uninstall haystack
then
pip install -U haystack-ai

I'm going ahead and close this issue, let us know if you keep hitting the same error after cleaning up your installation.

@masci masci closed this as completed Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants