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

Talk Python's Mastodon Michael Kennedy's Mastodon