Installing Django
00:00 In this lesson, you will learn how to install Django and also how to pin your dependencies and work with them.
00:07 So, this topic—installing Django and pinning your dependencies—has primarily two points to it. As you might expect, first, it’s installing Django, and second, it’s pinning your dependencies.
00:17 But there’s also something else I’m going to talk about, which is what do you do with pinned dependencies? So there will be a third topic, which is how do you install your pinned dependencies.
00:27 If you think about it from the opposite end that you maybe receive a Django project with a requirements file—that you will get to know in just a second—and then how do you install from there?
00:36 So it’s either when you’re starting from scratch, it’s going to be mostly installing Django and pinning your dependencies, but if you work on an existing project, then you might want to install pinned dependencies.
00:47
So, let’s take a look at that and let’s start by installing Django. The command for this is python3 -m pip
, so using the pip
module to install Django.
01:01 I will head over to VS Code and do that right away.
01:06
Over here, you see my virtual environment is activated and I can now go and say python3
, not python2
, -m pip install django
.
01:20
When I execute this command, then pip
makes a connection to PyPI, fetches the Django package, and installs it into the virtual environment. That’s why it’s important that you have that activated because otherwise it goes into your system install of Python, which you don’t want. Now, I’m not going to make you wait for this, so let’s skip through the time of install, and we’re done! So Django is installed,
01:47
using this command python3 -m pip install django
. That’s really all you need to do. One thing to remember, though, is that if you do this, then it installs the most recent version of Django.
01:58
Now you might wonder, “Okay, so what if you want a specific version of Django, maybe an older one? What do you do?” And you can do that as well. If you want to install a specific Django version, then you use the exact same command but you add something at the end, which is you define the version that you want to use, so a double equal sign (==
) and then a version number is going to make pip
install that specific version of Django. So this command would install the version 2.2.11
of Django.
02:29 Now in the next lesson, you’re going to learn about how to pin your dependencies, because in this case you would have a dependency of a specific Django version, so you want to make sure that this is also noted somewhere in your project—that if someone else uses your project, they know that they should work with Django 2.2.11 instead of the newest version. And to note this, you need to pin your dependencies.
Become a Member to join the conversation.