With your Python version selected, a virtual environment activated, and an understanding of managing dependencies using pip
and requirements.txt
, you are now ready to install the specific Python packages that form the backbone of many LLM applications. The Python ecosystem for LLM development is active and growing, but a few libraries are particularly significant for the workflows we will build in this course.
We will focus on installing the primary tools for orchestration, data handling, and API interaction.
These libraries provide high-level abstractions to structure LLM applications.
LangChain: This is a framework designed for developing applications powered by language models. It provides modular components for working with LLMs, managing prompts, chaining sequences of calls, interfacing with external data, and creating autonomous agents. We will use LangChain extensively for building and managing workflows.
To install the core LangChain package, use pip:
pip install langchain
LangChain maintains integrations with specific LLM providers and other tools in separate packages for better modularity. For example, to use OpenAI models with LangChain, you would install:
pip install langchain-openai
Similarly, for Anthropic models:
pip install langchain-anthropic
You can often install multiple extras at once:
pip install 'langchain[openai,anthropic]'
We will cover specific integrations as needed in later chapters. For now, installing the core langchain
and the provider package you intend to use (like langchain-openai
) is a good starting point.
LlamaIndex: This library focuses on connecting LLMs with external data sources. It excels at data ingestion (loading documents, web pages, etc.), indexing this data efficiently (often using vector embeddings), and providing query interfaces to retrieve relevant context for your LLMs. It's particularly useful for building Retrieval-Augmented Generation (RAG) systems.
Install LlamaIndex using pip:
pip install llama-index
LlamaIndex also has optional dependencies for specific data loaders, vector stores, or LLMs, which can be installed as needed.
While libraries like LangChain can abstract away direct API calls, you might sometimes need or prefer to use the official client libraries provided by LLM vendors. These offer direct access to the model provider's API endpoints.
pip install openai
pip install anthropic
Install the client libraries relevant to the LLM services you have access to and plan to utilize. Remember to handle the corresponding API keys securely, as discussed in the previous section.
Several other libraries are commonly used in LLM development workflows:
python-dotenv
: Useful for managing environment variables, especially for loading API keys from a .env
file into your environment.
pip install python-dotenv
requests
: The standard library for making HTTP requests in Python. While often wrapped by client libraries or frameworks like LangChain, it's good practice to have it available for direct API interactions or debugging. It's often installed as a dependency of other packages, but explicit installation doesn't hurt.
pip install requests
pip install chromadb
pip install faiss-cpu
chromadb
prepares your environment for RAG tasks.requirements.txt
After installing these essential libraries, it's important to update your requirements.txt
file to reflect the current state of your virtual environment. This ensures reproducibility.
Run the following command in your activated virtual environment:
pip freeze > requirements.txt
This command lists all installed packages and their exact versions, saving them to the requirements.txt
file. Your file might look something like this (versions will vary):
# requirements.txt
langchain==0.1.16
langchain-core==0.1.45
langchain-openai==0.1.3
llama-index==0.10.25
openai==1.16.1
python-dotenv==1.0.1
requests==2.31.0
chromadb==0.4.24
# ... other dependencies ...
Commit this updated requirements.txt
file to your version control system (e.g., Git).
You can perform a quick check to ensure the main libraries were installed correctly by starting a Python interpreter in your terminal (within the activated virtual environment) and importing them:
import langchain
import llama_index
import openai # Or another provider library you installed
print("Libraries imported successfully!")
If this runs without ModuleNotFoundError
, your core libraries are installed and ready.
Having installed these fundamental packages, your Python environment is now equipped for interacting with LLMs, building workflows, and handling external data. In the next chapter, we will start putting these to use by directly interacting with LLM APIs using Python.
© 2025 ApX Machine Learning