haystack icon indicating copy to clipboard operation
haystack copied to clipboard

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

Open ayush4921 opened this issue 1 year ago • 24 comments

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:

ayush4921 avatar Dec 28 '23 09:12 ayush4921

Hello, @ayush4921... Which version of Haystack are you using?

anakin87 avatar Dec 28 '23 10:12 anakin87

1.23.0 and 1.22.1. What's interesting is that, this issue only occurs when I use a python virtualenv environment. If I use conda, this issue doesn't occur.

ayush4921 avatar Dec 28 '23 10:12 ayush4921

Strange behavior...

I would suggest retrying in a clean virtual environment. Also, Haystack has not yet been tested with Python 3.11, so you may as well try using the 3.10 version.

anakin87 avatar Dec 28 '23 10:12 anakin87

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

MoFayaz avatar Dec 29 '23 04:12 MoFayaz

Did someone find a solution?

ayush4921 avatar Jan 01 '24 17:01 ayush4921

@MoFayaz

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

ayush4921 avatar Jan 02 '24 10:01 ayush4921

@anakin87 I tried using a conda enviroment with python 3.10.10 and the issue still persists.

ayush4921 avatar Jan 02 '24 11:01 ayush4921

Thanks. I will try to look at this issue later...

anakin87 avatar Jan 02 '24 11:01 anakin87

@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).

anakin87 avatar Jan 02 '24 14:01 anakin87

I ran

!pip install farm-haystack[colab,preprocessing,elasticsearch,inference]
from haystack.telemetry import send_event

in a fresh conda environment on MacOS but couldn't reproduce the issue. It works well for me with Apple M1.

julian-risch avatar Jan 02 '24 14:01 julian-risch

@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 avatar Jan 02 '24 17:01 MoFayaz

conda remove --name haystack_test --all conda create --name haystack_test python=3.10.10 conda activate haystack_test pip install 'farm-haystack[colab,preprocessing,elasticsearch,inference]' --no-cache-dir from haystack.nodes import JoinDocuments, SentenceTransformersRanker

Error faced:

File "/Users/ayushgarg/miniforge3/envs/haystack_test/lib/python3.10/site-packages/haystack/nodes/__init__.py", line 1, in <module>
from haystack.nodes.base import BaseComponent
File "/Users/ayushgarg/miniforge3/envs/haystack_test/lib/python3.10/site-packages/haystack/nodes/base.py", line 11, in <module>
from haystack.errors import PipelineSchemaError
ImportError: cannot import name 'PipelineSchemaError' from 'haystack.errors' (/Users/ayushgarg/miniforge3/envs/haystack_test/lib/python3.10/site-packages/haystack/errors.py)

ayush4921 avatar Jan 02 '24 17:01 ayush4921

To complete the information, see my (failed) attempt to reproduce the issue on Colab.

anakin87 avatar Jan 02 '24 17:01 anakin87

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.

ayush4921 avatar Jan 02 '24 17:01 ayush4921

Facing

Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0
Setting up cuda...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/ag6ys/answerThis/answerthis/demo.py", line 1, in <module>
    from answerthis.answerthis import Answerthis
  File "/home/ag6ys/answerThis/answerthis/answerthis.py", line 3, in <module>
    from haystack.nodes import JoinDocuments, SentenceTransformersRanker, PromptModel
  File "/home/ag6ys/.conda/envs/answerthis/lib/python3.11/site-packages/haystack/nodes/__init__.py", line 1, in <module>
    from haystack.nodes.base import BaseComponent
  File "/home/ag6ys/.conda/envs/answerthis/lib/python3.11/site-packages/haystack/nodes/base.py", line 11, in <module>
    from haystack.errors import PipelineSchemaError
ImportError: cannot import name 'PipelineSchemaError' from 'haystack.errors' (/home/ag6ys/.conda/envs/answerthis/lib/python3.11/site-packages/haystack/errors.py)
Finished at Tue Jan  2 13:20:57 EST 2024

On slurm as well.

ayush4921 avatar Jan 02 '24 18:01 ayush4921

Same error here, using venv, with python3.10 on Ubuntu 22.04:

Traceback (most recent call last):
  File "/mnt/c/Users/PedroVilaplana/Desktop/llm-rag-invoice-cpu/ingest.py", line 1, in <module>
    from haystack.nodes.retriever import EmbeddingRetriever
  File "/mnt/c/Users/PedroVilaplana/Desktop/llm-rag-invoice-cpu/venv/lib/python3.10/site-packages/haystack/__init__.py", line 11, in <module>
    from haystack.nodes.base import BaseComponent
  File "/mnt/c/Users/PedroVilaplana/Desktop/llm-rag-invoice-cpu/venv/lib/python3.10/site-packages/haystack/nodes/__init__.py", line 25, in <module>
    from haystack.nodes.prompt import PromptNode, PromptTemplate, PromptModel, BaseOutputParser, AnswerParser
  File "/mnt/c/Users/PedroVilaplana/Desktop/llm-rag-invoice-cpu/venv/lib/python3.10/site-packages/haystack/nodes/prompt/__init__.py", line 1, in <module>
    from haystack.nodes.prompt.prompt_node import PromptNode
  File "/mnt/c/Users/PedroVilaplana/Desktop/llm-rag-invoice-cpu/venv/lib/python3.10/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' (/mnt/c/Users/PedroVilaplana/Desktop/llm-rag-invoice-cpu/venv/lib/python3.10/site-packages/haystack/telemetry/__init__.py)

SDpedrovilaplana avatar Jan 03 '24 15:01 SDpedrovilaplana

@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

anakin87 avatar Jan 03 '24 16:01 anakin87

For those struggling with a similar problem, you likely have farm-haystack (1.x) and haystack-ai (2.x) in the same environment.

See this discussion for more information.

anakin87 avatar Jan 05 '24 12:01 anakin87

Config

  • System: Thinkpad
  • OS: Ubuntu 22.04 via Docker
  • Docker version: 24.0.5, build 24.0.5-0ubuntu1~20.04.1
  • GPU/CPU: CPU, no GPU
  • Haystack version (commit or version number): farm-haystack 1.24.0
  • DocumentStore: FAISSDocumentStore
  • Reader: FARMReader
  • Retriever: EmbeddingRetriever

I removed haystack-ai from my pip install under Docker and restricted my use of farm-hystack[...] by stripping down my app.

None of the solutions above worked.

I am still receiving the error: ImportError: cannot import name 'send_event' from 'haystack.telemetry' (.../python3.10/site-packages/haystack/telemetry/__init__.py)

Note that I was unable to install only Python3.9 in the Docker. As such, the Docker continues to install Python3.10

exowanderer avatar Jan 29 '24 00:01 exowanderer

I'm also facing the same issue in windows does anyone got solution ?

Kunjesh07 avatar Jan 29 '24 07:01 Kunjesh07

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.

ayush4921 avatar Jan 29 '24 08:01 ayush4921

Here is my Dockerfile:

ENV PATH="/usr/local/cuda/bin:${PATH}"
ENV HAYSTACK_TELEMETRY_ENABLED="False"

# Install ollama llm inference engine
RUN curl https://ollama.ai/install.sh | sh

# Install fastapi and web server
RUN pip install fastapi
RUN pip install "uvicorn[standard]"

# RAG framework haystack
RUN pip install --upgrade pip
RUN pip install ollama-haystack
# RUN pip install farm-haystack[faiss,preprocessing,elasticsearch,inference]
RUN pip install farm-haystack[all]
RUN pip uninstall -y haystack-ai

I added pip uninstall -y hastack-ai above and below pip install farm-haystack[.. options...]

My run configure is the following:

  1. DOCKER_BUILDKIT=1 docker build . -t gbnc
  2. docker run -p 8000:8000 --rm -it gbnc

During the docker run command, haystack presents one of two errors every time:

  1. If pip uninstall -y haystack-ai is before the pip install Dockerfile sequence, then haystack presents:

ImportError: cannot import name 'send_event' from 'haystack.telemetry' (/usr/local/lib/python3.10/dist-packages/haystack/telemetry/init.py)

  1. If pip uninstall -y haystack-ai is after the pip install Dockerfile sequence, then haystack presents:

ImportError: cannot import name 'version' from 'haystack' (unknown location)

Are they connected? Is there a fix for the second error that lets us complete the solution for the first error ("send_message" error)?

Thank you in advance

exowanderer avatar Jan 29 '24 17:01 exowanderer

Hello, @exowanderer!

  • haystack-ai (Haystack 2.0-beta) and farm-haystack (Haystack 1.x) are mutually exclusive
  • ollama-haystack is based on haystack-ai

More information on Haystack 2.0-beta in this discussion.

If you want to use Haystack 2.0-beta + Ollama, you can modify your Dockerfile as follows (untested):

ENV PATH="/usr/local/cuda/bin:${PATH}"
ENV HAYSTACK_TELEMETRY_ENABLED="False"

# Install ollama llm inference engine
RUN curl https://ollama.ai/install.sh | sh

# Install fastapi and web server
RUN pip install fastapi
RUN pip install "uvicorn[standard]"

# RAG framework haystack
RUN pip install --upgrade pip
RUN pip install ollama-haystack

Haystack 1.x does not support Ollama out of the box.

If you need more information, ask for it in this thread if related or open a discussion. :heart_decoration:

anakin87 avatar Jan 29 '24 18:01 anakin87

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.

exowanderer avatar Feb 09 '24 13:02 exowanderer

@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.

sutgeorge avatar Feb 22 '24 07:02 sutgeorge