Module 1 Lesson 1: Python and Virtual Environments
The starting point. How to set up a clean, isolated Python environment for your LangChain projects.
Setting Up Your Environment
Before we dive into LangChain, we must ensure your Python environment is clean and isolated. In the world of AI engineering, dependency conflicts are common. A Virtual Environment ensures that the libraries you install for LangChain don't break your other Python projects.
1. Why Virtual Environments?
Imagine you have Project A using LangChain v0.1 and Project B using LangChain v0.3. If you install them globally, one will break. Virtual environments create a local "Folder" for your libraries.
2. Creating a Virtual Environment
Open your terminal and navigate to your project directory. Run:
# Create the environment
python -m venv venv
3. Activating the Environment
You must "Enter" the environment before using it.
On macOS / Linux:
source venv/bin/activate
On Windows:
.\venv\Scripts\activate
Once activated, you will usually see (venv) in your terminal prompt.
4. Verifying Python
Ensure you are using Python 3.9 or higher, as many LangChain features require modern Python syntax.
python --version
Key Takeaways
- Isolation is key to avoiding "Dependency Hell."
python -m venvis the standard tool for creating environments in Python.- Always Activate your environment before installing any packages.
- LangChain works best with Python 3.9+.