Python for Absolute Beginners Transcripts
Chapter: Using external Python packages
Lecture: Managing requirements with the requirements.txt file

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now that we've got our virtual environment here
0:02 we're ready to use colorama
0:03 there's still one more step that we should take.
0:06 There's nothing requiring us to take this at the moment
0:09 but in the future you're going to
0:10 be really glad that you did.
0:11 So, one of the things that's important is for us
0:13 to express to other automated systems
0:17 other developers or users who get this code
0:20 and want to run it, that this code now is going
0:22 to require colorama.
0:26 If we don't have colorama installed and we run it
0:28 what's going to happen?
0:29 It's going to crash and say we don't know what colorama means.
0:32 So in order for us to make that clear
0:34 like this program must have colorama
0:37 or whatever other external package is installed
0:40 there's a convention that all the tooling understands.
0:43 Come over here and add a new blank file
0:45 called requirements.txt.
0:49 And down here all we have to do is put
0:52 the same command we would type to pip install whatever
0:55 into this file we just put the whatever.
0:58 So in this case we just put colorama.
1:00 Notice that PyCharm is saying there's a thing we need you
1:03 to install called Colouram, well no that's not true
1:05 and once we put colorama it's good.
1:07 This squiggly, just PyCharm thinks it's misspelled
1:10 which is weird, but if we also depended upon requests
1:13 we could have it like that
1:15 and if we click this button it's the same as if
1:17 we went and activated the virtual environment
1:20 and said pip install request
1:21 but we're not actually going to do that here.
1:24 Let's go and just see how we might add another library
1:26 that we're not going to use yet
1:28 but we're going to use eventually this thing
1:29 called prompt_toolkit.
1:32 Now if we go down here to the terminal
1:34 it should have the virtual environment activated.
1:37 You can double check by saying which or where Python
1:39 and it's going to be the one in that folder, if it's right.
1:42 So if we come down here and say pip list
1:45 you can see here's colorama, but not prompt_toolkit.
1:48 Also if you go to this UI bit here's colorama
1:50 but not prompt_toolkit.
1:52 All we do is click this, PyCharm knows, hey
1:56 I told you the tooling understands requirements.txt
1:58 it knows that this means something
2:00 if we click it, it's going to go and say
2:02 hey that got installed okay.
2:03 If we go back to the UI
2:05 look here now prompt_toolkit is installed
2:08 similarly if we look at it this way
2:11 we say pip list, we now have prompt_toolkit.
2:14 We're not using that yet
2:15 but those are the two we're going to need
2:16 so I put them into our requirements file, right here.
2:19 That's cool, right?
2:20 So we've got this requirements file
2:21 that any time you get this code out and you want to run it
2:24 you just can say actually there's a way
2:26 to say install everything I need from here
2:28 as well as pip install dash R, or our requirements file
2:32 requirements.txt and it tries to install all the things.
2:36 We saw that's basically what PyCharm did
2:37 it looked and said there's some stuff that's missing
2:39 click this button and I'll run that command for you.
2:42 That's the requirements.txt and you should always have one
2:45 any time you're using an external package.