Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Installing Your Requirements

00:00 In the previous lesson, you learned how to pin your dependencies with this command and also why you would want to do it—in order to keep track of the specific versions that you’re using. In this lesson, you’re going to learn how to install your pinned dependencies. Now, the command for this is python3 -m pip install, so similar to installing Django, but then instead of specifying the name django here, you’re going to say “Read from the requirements.txt file,” so -r and then pass the name of the file, which by default is going to be requirements.txt.

00:35 In order to actually show you how this happens, I’m going to go over here and delete the virtual environment that I have so far, just as a little practice to redo everything and kind of, like, simulate how it would be like if you download a project and all you have is this requirements.txt file.

00:52 So, let me deactivate, deactivate, the virtual environment. You see, this is gone, the prepended thing is gone, so now it’s deactivated and now I will remove the folder.

01:11 And here you can see that that’s the useful thing about using a virtual environment—that once I delete this, anything that was installed in there is gone and it didn’t pollute my system anywhere else. So I go ahead and recreate a new virtual environment with the same command and .venv.

01:31 You’ll see it pop up again.

01:34 Then you also need to activate it once it’s finished,

01:43 bin/ and activate. Again, now you’re inside of the virtual environment, but nothing is installed so far. So if I say python3 -m pip freeze, you remember before it showed the different packages that came with Django—including Django—and now I don’t get any output because there’s nothing installed yet.

02:06 So now I want to install… Because I made this nice file, requirements.txt, that comes with the so-far empty project, I want to install any package that’s noted in here.

02:21 And as we said before—let’s double-check on the command—the command is python3 -m pip install, -r for read, requirements.txt. I’m going to do this over here now.

02:34 python3 -m pip install, read the requirements.txt file. So I’m using autocomplete here with the Tab key to make it a little easier. And now it’s reading, you can see it’s installing asgiref, Django of that specific version, just as it’s noted inside of the requirements.txt file.

03:02 All right! So once this install is finished, I’m going to have the same environment as I had before, the one that I froze with the command, and this is why it’s helpful to pin your dependencies and also how to install it from pinned dependencies.

03:20 So, in these last two lessons, you learned how to install Django and pin your dependencies. First, you did the command to install Django, then you pinned your dependencies, and then we took this little detour to also learn how to install from pinned dependencies. Next up, in the next lesson, you will learn to finally set up a Django project.

Become a Member to join the conversation.