Loading video player…

Setting Up LangChain

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.

Avatar image for Ruben Decrop

Ruben Decrop on Aug. 3, 2026

Apparently, we need the Rust compiler to run pip install. This should be mentioned.

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Aug. 6, 2026

@Ruben Decrop, thanks for the report. A note is worth adding, though a Rust toolchain isn’t actually a requirement for this course. What you hit is pip falling back to building from source.

Most of these packages ship prebuilt wheels. The Rust-based ones in this dependency tree are pydantic-core (through langchain) and tiktoken (through langchain-openai). When a matching wheel exists for your platform and Python version, pip just downloads it and no compiler is involved. The cargo errors only show up when pip can’t find a matching wheel and tries to compile instead.

Two things usually cause that:

  1. An outdated pip that doesn’t recognize newer wheel tags. Worth ruling out first: $ python -m pip install --upgrade pip
  2. A Python version newer than the pinned packages support. This is my main suspicion here, because the lesson recommends pinning to the versions shown at 01:22 and in the requirements.txt from the Supporting Material dropdown. Those pins are from when the course was recorded, so an older pydantic-core or tiktoken won’t have wheels for a Python release that came out afterward. Relaxing those two pins, or using a slightly older Python, usually clears it.

If neither helps, could you share which package failed along with your Python version and OS? It’s also useful to know if you’re on Alpine or another musl-based Linux, where prebuilt wheels often aren’t available and building from source is expected.

I’ll pass this on to the rest of the team either way. A note about the pinned versions aging out is a reasonable addition to the lesson.

Become a Member to join the conversation.