ModuleNotFoundError
ModuleNotFoundError: No module named 'haystack.document_stores.in_memory'
Stack trace
Traceback (most recent call last):
File "app.py", line 5, in <module>
from haystack.document_stores import InMemoryDocumentStore
ModuleNotFoundError: No module named 'haystack.document_stores.in_memory' Why it happens
Haystack's InMemoryDocumentStore class is either not installed or the import path has changed in newer versions. This error typically happens if the haystack package is not installed correctly or if the import statement uses an outdated or incorrect module path.
Detection
Check your import statements and verify that the haystack package is installed in your environment. Use pip list or pip show farm-haystack to confirm installation before running the code.
Causes & fixes
Haystack package is not installed in the Python environment
Install Haystack using pip: pip install farm-haystack to ensure all modules including InMemoryDocumentStore are available.
Incorrect import path for InMemoryDocumentStore due to version changes
Update the import statement to 'from haystack.document_stores import InMemoryDocumentStore' as per the latest Haystack documentation.
Using an outdated Haystack version where InMemoryDocumentStore was in a different module
Upgrade Haystack to a recent version (>=1.0.0) where InMemoryDocumentStore is available under haystack.document_stores.
Code: broken vs fixed
from haystack.document_stores.in_memory import InMemoryDocumentStore # causes ModuleNotFoundError
store = InMemoryDocumentStore()
print("Store initialized") import os
from haystack.document_stores import InMemoryDocumentStore # fixed import path
store = InMemoryDocumentStore()
print("Store initialized") Workaround
If upgrading or reinstalling is not possible, manually check the installed haystack package directory for InMemoryDocumentStore location and adjust import paths accordingly.
Prevention
Always verify the Haystack version and consult official docs for import paths after upgrades to avoid module not found errors.