haystack: ImportError: cannot import name 'send_event' from 'haystack.telemetry'

Describe the bug When I try to import haystack from pipeline from haystack import Pipeline, I get this error. Error message ImportError: cannot import name ‘send_event’ from ‘haystack.telemetry’ (/Users/ayushgarg/projects/answerthis_prod/venv/lib/python3.11/site-packages/haystack/telemetry/init.py)

Expected behavior Telemetry should run as expected.

To reproduce

Make a file with “from haystack import pipelines”. Try to run it.

  File "/Users/ayushgarg/projects/answerthis_prod/demo.py", line 1, in <module>
    from haystack import pipelines
  File "/Users/ayushgarg/projects/answerthis_prod/venv/lib/python3.11/site-packages/haystack/__init__.py", line 11, in <module>
    from haystack.nodes.base import BaseComponent
  File "/Users/ayushgarg/projects/answerthis_prod/venv/lib/python3.11/site-packages/haystack/nodes/__init__.py", line 3, in <module>
    from haystack.nodes.answer_generator import BaseGenerator, OpenAIAnswerGenerator
  File "/Users/ayushgarg/projects/answerthis_prod/venv/lib/python3.11/site-packages/haystack/nodes/answer_generator/__init__.py", line 2, in <module>
    from haystack.nodes.answer_generator.openai import OpenAIAnswerGenerator
  File "/Users/ayushgarg/projects/answerthis_prod/venv/lib/python3.11/site-packages/haystack/nodes/answer_generator/openai.py", line 9, in <module>
    from haystack.nodes.prompt import PromptTemplate
  File "/Users/ayushgarg/projects/answerthis_prod/venv/lib/python3.11/site-packages/haystack/nodes/prompt/__init__.py", line 1, in <module>
    from haystack.nodes.prompt.prompt_node import PromptNode
  File "/Users/ayushgarg/projects/answerthis_prod/venv/lib/python3.11/site-packages/haystack/nodes/prompt/prompt_node.py", line 8, in <module>
    from haystack.telemetry import send_event
ImportError: cannot import name 'send_event' from 'haystack.telemetry' (/Users/ayushgarg/projects/answerthis_prod/venv/lib/python3.11/site-packages/haystack/telemetry/__init__.py)

FAQ Check Yes

System:

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

About this issue

  • Original URL
  • State: closed
  • Created 6 months ago
  • Reactions: 1
  • Comments: 25 (9 by maintainers)

Most upvoted comments

My apologies for the delay. I was distracted by life.

Thank you @anakin87, your info and suggestions led us in the right direction. Indeed, we were blending Haystack 1.x and 2.0beta. We had to re-write a few things and only use Haystack 2.0beta with ollama.

Unrelated to this issue, we can thus only use InMemoryDocumentStore instead of FAISSDocumentStore. As such, we don’t see the option to store the embeddings in an SQL db or FAISS index.

All the same, the code works and follows our requirements. Maybe we don’t need to the other bells and whistles.

Solved for my team.

@SDpedrovilaplana thanks to your report, I finally managed to reproduce this issue!!!

It seems related to installing farm-haystack (haystack 1.x) and haystack-ai (haystack 2.x) in the same virtual environment, which I think should be discouraged.

To reproduce

! pip install farm-haystack haystack-ai
import haystack

@SDpedrovilaplana thanks to your report, I finally managed to reproduce this issue!!!

It seems related to installing farm-haystack (haystack 1.x) and haystack-ai (haystack 2.x) in the same virtual environment, which I think should be discouraged.

To reproduce

! pip install farm-haystack haystack-ai
import haystack

Thank you, this solved my issue.

It’s because you have haystack-ai and farm-haystack installed in the same environment. This issue took me a long time to figure out, but just pip uninstall haystack-ai.

I am not sure as to why the error is not happening on colab. Even on my system, the error is inconsistent. My guess is, it has to do with the way the package is being installed. All the functions that are not being able to be imported do exist, so somehow the structure of the package is being changed.

@MoFayaz Easiest steps to reproduce: !pip install farm-haystack[colab,preprocessing,elasticsearch,inference] from haystack.telemetry import send_event

I have tried the same on Ubuntu 22.04, with Python 3.8.18 and 3.10.12 and I cannot reproduce the issue. I will ask someone who has access to macOS (on Discord, @ayush4921 referred to M1 Pro).

still getting this issue after using both of the mentioned Python versions on Ubuntu 22.04. I’m trying to install farm-haystack[weaviate] and farm-haystack

@MoFayaz

Easiest steps to reproduce: !pip install farm-haystack[colab,preprocessing,elasticsearch,inference] from haystack.telemetry import send_event

Same issue here. I’m using python 3.10 and trying in conda environment