Loading video player…

Setting Up LangChain

Resources to explore:

00:00 Let’s start right away. The first step is to create and activate a virtual environment and then install the dependencies.

00:09 Create a virtual environment that I’ll call venv using Python 3.13 in this case. And then I’ll go ahead and activate it by running source ./venv/bin/activate.

00:23 The command is slightly different on Windows, and here I’m working on a macOS so on a Unix machine. You can see that the virtual environment is activated by the prepend name of the virtual environment on the left.

00:34 So here it says venv. And now I’ll go ahead and install the dependencies by typing python -m pip install. And then we wanted langchain langchain-openai,

00:48 openai, and python-dotenv, which is just for handling the environment variables.

00:55 Now you’ll have to wait for these dependencies to install. Once it’s done, you can type python -m pip list to confirm that you have a bunch of dependencies in your virtual environment, and these are the direct dependencies that you installed explicitly, and the transitive dependencies for those packages.

01:16 And if you want to know the exact versions of the direct dependencies that I’ve used in this course, here’s a list of them. And you can also get them from a requirements.txt file when you download the supporting materials.

01:27 And I’m showing you these exact dependencies here because these packages are in active development. So version changes might happen quite frequently, and they might introduce breaking changes.

01:37 So if you want to make sure to work along exactly how I’m doing it in this course, then make sure to pin your dependencies and use these ones. They might work with newer versions, but there might be some differences.

01:49 Next, you’ll need to get an OpenAI API key and put that key into your .env file. You don’t have to use OpenAI, you can use any other LLM API provider or even a local LLM. Langchain is able to work with all of those.

02:03 But in this course, I’ll work with OpenAI. So if you want to follow along exactly again, then you should get that API key. Otherwise, there’s just some small changes you need to do.

02:12 Once you have the keys, you should put them in your .env file. So make a new file, call it .env, and then paste it in there. This is literally going to be just the name of the environment variable, in this case, OPENAI_API_KEY and an equal sign, and then pasting the key in there.

02:31 Let me show you mine here. Well, not actually mine, don’t get too excited. So there’s not the real key in here, but it’ll really just look like this. The file is called .env, and then the name of the environment variable and followed by an equal sign and your key. With this, you’re set up and ready to go, but I’m going to tell you about one more optional dependency, which is ptpython.

02:56 That’s an alternative Python REPL because I’ll be using the REPL heavily in this course, so I’ll do all the coding in the REPL. And ptpython just provides a somewhat nicer experience, better syntax highlighting, so it’ll make it easier for you to follow along.

03:10 You don’t have to install ptpython. Feel free to just use the built-in Python REPL or work in scripts if you want to. But I’m going to be using ptpython again, if you want to follow along exactly, you can also install that alternative Python REPL.

03:25 And finally, I want to mention the resources. You can get the sample code that includes all the code that I’m going to run in this course from the downloadable resources on the course overview page, or from the supporting material dropdown that you can find on each lesson page under the video.

03:40 So get that sample code so that you can follow along.

03:44 Alright, with this, you’re ready with the setup. And in the next lesson, you’ll start looking at LangChain chat models.

Become a Member to join the conversation.