Pinning Your Dependencies
00:00 After successfully installing the most recent version of Django in the previous lesson, you will now learn how to pin your dependencies to make sure that anyone using your project in the future knows what version of Django you were working with.
And the command for doing this is
python3 -m pip, and then the
freeze command, and then you’re piping the output of this command into a new file called
requirements.txt. And this is just the name of a file but it is a standard naming for a place where you want to keep track of your requirements for a Python project. All right, let’s do this. Over here, you see all the mess from installing Django, so I’ll clear that up. And now run the command
python3 -m pip freeze. And before I’m actually piping it into the requirements file, let’s just see what the output of this is. If I run this command, it’s going to tell me which are the packages that are currently installed.
You can see that
django==3.2.2 is the current version of Django at the time of recording this video. I only explicitly installed Django and I didn’t even specify a version, I just said, “Give me the most recent one.” And it also installed some other dependencies that Django has.
So, Django always needs these other packages, so if you go and install Django, then they also come with it. Now, I want to make sure that someone else using this package is also going to know that it was built with Django 3.2.2, so I need to put the output of this
freeze command somewhere.
02:07 It just pins, it just notes what are the dependencies necessary for running this project. Cool! So now you can commit this to version control together with the rest of your project files and anyone who wants to work with your project can just go ahead and install the necessary requirements by reading them from the requirements file. Now, how to do that, you’re going to learn about in the next lesson.
Become a Member to join the conversation.