Skip to content

Installation

Prerequisites

  • Python 3.11+ (Python 3.12 recommended for development)
  • MongoDB running locally or remotely
  • An OpenAI API key (or another LangChain-compatible LLM)

LongTrainer 1.4.0 requires Python 3.11 or newer. Python 3.10 users must upgrade their Python environment before installing this version.

Install LongTrainer

pip install longtrainer

With Agent Mode Support (Optional)

Agent mode requires LangGraph for tool calling:

pip install longtrainer[agent]

With Observability & Hallucination Detection (Optional)

LongTracer integration provides tracing spans and CitationVerifier-based hallucination detection:

pip install longtrainer[tracer]

System Dependencies

Some document loaders require system-level libraries for parsing PDFs, images, and office files.

Linux (Ubuntu/Debian)

sudo apt install libmagic-dev poppler-utils tesseract-ocr qpdf libreoffice pandoc

macOS

brew install libmagic poppler tesseract qpdf libreoffice pandoc

Note

System dependencies are only required if you plan to load documents using use_unstructured=True or process PDFs, images, and office formats.

Verify Installation

import longtrainer
print(longtrainer.__version__)  # Should print "1.3.1"

from longtrainer import LongTrainer, ToolRegistry, web_search
print("LongTrainer 1.3.1 installed successfully!")

Environment Variables

Set your OpenAI API key before using LongTrainer:

import os
os.environ["OPENAI_API_KEY"] = "sk-..."

Or export it in your shell:

export OPENAI_API_KEY="sk-..."