1 00:00:00,000 --> 00:00:01,770 Let's talk about requirement files. 2 00:00:01,780 --> 00:00:07,080 In most projects that use Python, they're going to have dependencies 3 00:00:07,090 --> 00:00:07,860 that come with it. 4 00:00:07,870 --> 00:00:12,060 So if you look at a project on GitHub that has a bunch of 5 00:00:12,060 --> 00:00:16,000 Python in it, chances are it comes with this thing called 'requirements.txt' file, 6 00:00:16,000 --> 00:00:21,000 or some sort of '.txt' file. Usually by convention 7 00:00:21,000 --> 00:00:23,700 we just call 'requirements.txt' 8 00:00:23,700 --> 00:00:26,700 So if you ever see a 'requirements.txt' file, you can always 9 00:00:26,710 --> 00:00:29,640 'pip install' all the files, or all the dependencies that are 10 00:00:29,650 --> 00:00:33,330 in there with 'pip install -r', and then the 'requirements.txt' 11 00:00:33,340 --> 00:00:35,400 file. Now, currently, we don't have that, 12 00:00:35,410 --> 00:00:36,990 at least I don't have that on my Desktop. 13 00:00:37,000 --> 00:00:41,120 So what I'm going to do, we'll just create a brand new file in 14 00:00:41,120 --> 00:00:46,700 here. I'm going to save it to my Desktop as 'requirements.txt', 15 00:00:46,700 --> 00:00:51,750 and in here I'm going to want Wagtail 2.8 as my Content 16 00:00:51,760 --> 00:00:52,560 Management System, 17 00:00:52,570 --> 00:00:58,420 maybe I want to use Django 2.2., something rather, and 18 00:00:58,900 --> 00:01:03,000 I don't know why, but maybe I want to also install Colorama, 19 00:01:03,000 --> 00:01:05,800 but I don't want to install a particular version of Colorama, 20 00:01:05,890 --> 00:01:06,989 I just want the latest one. 21 00:01:07,000 --> 00:01:10,230 So I'm not going to pin this with a particular version, 22 00:01:10,240 --> 00:01:13,450 that's what this is called when you use exact version types. 23 00:01:13,460 --> 00:01:14,650 That's called version pinning. 24 00:01:14,740 --> 00:01:16,990 So I have three packages that I want to install. 25 00:01:17,000 --> 00:01:22,790 I could run 'pip install -r requirements.txt', but that's going 26 00:01:22,800 --> 00:01:25,190 to install all that stuff on my computer, not in a virtual 27 00:01:25,200 --> 00:01:29,220 environment. So like in the last lesson, I'm going to create 28 00:01:29,220 --> 00:01:30,900 a new virtual environment real quickly. 29 00:01:30,900 --> 00:01:34,200 'python -m venv .venv', 30 00:01:34,200 --> 00:01:37,400 [no audio] 31 00:01:37,400 --> 00:01:40,900 and 'source .venv/bin/activate'. 32 00:01:40,920 --> 00:01:45,240 Now if we do 'ls -la', we can see, I've got 'requirements.txt' 33 00:01:45,240 --> 00:01:47,200 file. And let's just cat that out to the terminal 34 00:01:47,200 --> 00:01:51,600 ''requirements.txt' with the command 'cat'. 35 00:01:51,600 --> 00:01:55,200 And that shows me 'Django2.2.', something, 36 00:01:55,200 --> 00:01:57,700 'wagtail2.8', and 'Colorama' 37 00:01:57,710 --> 00:01:58,810 So now let's go ahead, 38 00:01:58,810 --> 00:02:01,500 now that I'm inside of my virtual environment, let's run 39 00:02:01,500 --> 00:02:04,200 'pip install -r'. 40 00:02:04,200 --> 00:02:06,600 You need the '-r' when you're using a file, 41 00:02:06,660 --> 00:02:09,630 'requirements.txt', and it's going to go ahead and download 42 00:02:09,630 --> 00:02:10,300 all these for me. 43 00:02:10,300 --> 00:02:15,900 [no audio] 44 00:02:15,900 --> 00:02:18,200 So while it's doing that, it's also going to download other 45 00:02:18,290 --> 00:02:19,330 dependencies that I need. 46 00:02:19,400 --> 00:02:23,330 So Django might have other packages that it needs, 47 00:02:23,560 --> 00:02:25,840 Wagtail probably has other packages it needs, 48 00:02:25,930 --> 00:02:29,700 Colorama might also need other packages, and these dependencies 49 00:02:29,710 --> 00:02:33,150 are packages that help make the main package work. 50 00:02:33,300 --> 00:02:39,800 So now if I do 'pip freeze', you can see I have all sorts of stuff in here. 51 00:02:39,880 --> 00:02:43,060 I definitely have more than just the three that I specified, 52 00:02:43,060 --> 00:02:45,800 and that's because a lot of these are going to be dependencies. 53 00:02:45,800 --> 00:02:50,830 Now, if you ever 'pip install' some new package always add it 54 00:02:50,830 --> 00:02:52,800 to your 'requirements.txt' file. 55 00:02:52,840 --> 00:02:56,170 If you're using 'pipenv', all you have to do is 'pipenv install', 56 00:02:56,180 --> 00:02:57,220 and then the package name, 57 00:02:57,230 --> 00:03:00,420 and it should update your 'pipfile.lock' for you, 58 00:03:00,430 --> 00:03:02,040 and you don't have to worry about that. 59 00:03:02,050 --> 00:03:04,290 But when we're using regular 'pip', we do. Now, 60 00:03:04,300 --> 00:03:07,950 the other thing we can do, is if we want all of these in here, 61 00:03:07,950 --> 00:03:10,300 we could copy and paste and put it in here, 62 00:03:10,360 --> 00:03:12,910 or we can use the command line way, 63 00:03:12,920 --> 00:03:16,050 and we can do 'pip freeze >', 64 00:03:16,060 --> 00:03:18,360 and that just means whatever comes out of here, 65 00:03:18,370 --> 00:03:19,410 that's all this stuff, 66 00:03:19,410 --> 00:03:21,200 we're going to jam it into a file. 67 00:03:21,200 --> 00:03:24,000 We're going to call that file 'requirements.txt', 68 00:03:24,600 --> 00:03:28,800 and you can see behind me here that this automatically updated 69 00:03:28,800 --> 00:03:30,900 with all the new packages. 70 00:03:30,940 --> 00:03:35,200 So now when you're working on another project and you push 71 00:03:35,210 --> 00:03:38,680 it up to GitHub or GitLab or wherever you're storing your 72 00:03:38,690 --> 00:03:41,390 code, someone else can have this 'requirements' file, 73 00:03:41,400 --> 00:03:44,510 and they can simply run 'pip install -r requirements', 74 00:03:44,690 --> 00:03:47,780 and they will get every single version in here. They will 75 00:03:47,780 --> 00:03:51,100 have the exact same environment that you have.