How to install Langchain on an M2 Macbook

and develop a simple Q/A app.

Roman Orac


Photo by Patrick Tomasso on Unsplash

Recently I started playing with Langchain, which is a popular framework for large language models. Langchain enables you to quickly create a chatbot (or an agent) by using OpenAI’s ChatGPT.

While installing Langchain on an M2 Macbook is quite straightforward with:

pip install langchain

The problem arose later on when I tried to develop a simple app, which answers questions from a text document:

import os
import glob
from langchain.document_loaders import TextLoader
from langchain.indexes import VectorstoreIndexCreator
from langchain.chat_models import ChatOpenAI


loader_list = []
for filepath in glob.glob('*.txt'):
loader = TextLoader(filepath)

index = VectorstoreIndexCreator().from_loaders(loader_list)

def answer_promth(prompt):
return index.query(prompt, llm=ChatOpenAI())

The chroma DB is the AI-native open-source embedding database. The app uses it for memory.

While running the code above on an M2 Macbook you might encounter an error:

ValueError: Could not import chromadb python package. Please install it with `pip install chromadb`.