ImportError with chromadb in Python 3.12.0 - Module Not Found Despite Installation

137 views Asked by At

I am working on a project involving text document processing, chunk creation, and embedding, with the intention of storing these in a vector database using ChromaDB. My development environment is VSCode, and I'm using Python 3.12.0. Despite having installed ChromaDB version 0.4.0, I am encountering an import error.

Here's a simplified version of my code:

from langchain_community.document_loaders import TextLoader, DirectoryLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_openai import OpenAIEmbeddings
from langchain_community.vectorstores import Chroma

# Code to load documents
text_loader_kwargs = {'autodetect_encoding': True}
loader = DirectoryLoader("./new_articles/", glob="./*.txt", loader_cls=TextLoader, loader_kwargs=text_loader_kwargs)
documents = loader.load()

# Code to create chunks
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
text = text_splitter.split_documents(documents)

# Code for embedding and storing in ChromaDB
embeddings = OpenAIEmbeddings()
persist_directory = 'db'
vectordb = Chroma.from_documents(documents=text, embedding=embeddings, persist_directory=persist_directory)

print(vectordb)

However, when I run this script, I receive the following error:

import chromadb.config
ModuleNotFoundError: No module named 'chromadb.config'; 'chromadb' is not a package

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  # Stack trace leading to ImportError for chromadb not being found...

I've already run pip install chromadb, and the package shows up in my environment's list of installed packages. I've tried re-installing the package and checking for any naming conflicts in my project directory, but the issue persists.

Question: How can I resolve the ModuleNotFoundError and ImportError for ChromaDB in this setup? Is there a compatibility issue with Python 3.12.0, or am I missing a step in the installation process?

Environment Details:

Python Version: 3.12.0 ChromaDB Version: 0.4.0 Development Environment: VSCode Any insights or suggestions would be greatly appreciated!

0

There are 0 answers