haystack
haystack copied to clipboard
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:
Hello, @ayush4921... Which version of Haystack are you using?
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.
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.
Same issue here. I'm using python 3.10 and trying in conda environment
Did someone find a solution?
@MoFayaz
Easiest steps to reproduce:
!pip install farm-haystack[colab,preprocessing,elasticsearch,inference]
from haystack.telemetry import send_event
@anakin87 I tried using a conda enviroment with python 3.10.10 and the issue still persists.
Thanks. I will try to look at this issue later...
@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).
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.
@MoFayaz Easiest steps to reproduce:
!pip install farm-haystack[colab,preprocessing,elasticsearch,inference]from haystack.telemetry import send_eventI 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
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)
To complete the information, see my (failed) attempt to reproduce the issue on Colab.
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.
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.
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 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
For those struggling with a similar problem, you likely have farm-haystack (1.x) and haystack-ai (2.x) in the same environment.
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
I'm also facing the same issue in windows does anyone got solution ?
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.
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:
DOCKER_BUILDKIT=1 docker build . -t gbncdocker run -p 8000:8000 --rm -it gbnc
During the docker run command, haystack presents one of two errors every time:
- If
pip uninstall -y haystack-aiis before thepip installDockerfile sequence, then haystack presents:
ImportError: cannot import name 'send_event' from 'haystack.telemetry' (/usr/local/lib/python3.10/dist-packages/haystack/telemetry/init.py)
- If
pip uninstall -y haystack-aiis after thepip installDockerfile 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
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:
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) andhaystack-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.