Effective PyCharm Transcripts
Chapter: PyCharm Projects
Lecture: Installing third-party packages

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's jump back to our simple first project over here. It just says Hello World. But what if we made it do something more interesting
0:07 Check this out over here. We have at wheather.talkpython.fm. There's a cool little API that if you click on it and you put
0:15 your city state country and units and stuff, you'll get the forecast for your location back. So what if we wanted to say Hello World.
0:24 Currently it is whatever the temperature is out there. So this is easy to do right import requests. We're gonna use requests and wait a minute.
0:33 There's an error. That doesn't make a lot of sense. If we go down here, notice there's a Python packages and you can see what's
0:39 installed. Well, we just have wheel and set up tools that's missing requests. And if we could actually go over here,
0:47 we could go find popular things like requests and I could install it this way. You could say add a package.
0:52 You go get type requests and just get it this way as well, right at the top, click install. But then the next person who gets it,
1:01 the next person who checks out this code or even if that next person is you on a different machine, it's not going to know that it needs it.
1:07 So a real common way. And what I'm doing these days is I'll make sure I'll have a requirements.txt file and in there,
1:17 I'll put things like requests and now notice PyCharm automatically knows what is installed here Into our packages installed. Ones.
1:29 there's nothing called that. But there's these two that are installed. These three, they're installed. They're not what we need but it knows it will
1:36 install. If we just click this button. So that would be the equivalent of coming over here saying pip
1:41 install - our requirements, notice we have our terminal. This is my 'Oh-My-Zshell' with all the history and everything because this is my
1:49 real shell. I could click this and of course that will install request as you probably know. Or I could just click this button,
1:56 wait for a moment down here, notice this and now requests and all the other things like if I had 'TQDM' was there as well,
2:04 which is like a cool progress bar. It would also have installed both of those at the same time. So that's super cool. That's part of the project.
2:15 Understanding that PyCharm does it knows at the top of our project,
2:19 we've got this requirements file and this describes what you need to get your project going after you've created your virtual environment.
2:26 So what the heck, let's go ahead and just write this real quick cause it'll be fun if we want to call it API
2:31 will go over and say the 'resp=requests.get' the URL, which is that great giant long thing then we can 'resp.raise_for_status( )'
2:41 to make sure it worked. And we'll say 'data = resp.json' and I've honestly forgotten what this looks like.
2:49 So what we need to do is go look at the raw data so we'll get the forecast and then the temp Say 'temp = data['forcast'] of ['temp']
3:03 and just hope that it's there. Make that an F string, give it a go look at that right now. It is summertime. And those are Fahrenheit.
3:14 Hopefully not Celsius. Hello world, it's 85 F outside. Lovely, lovely. Okay, so when we work with these external libraries,
3:23 the simplest and most straightforward is to just have these requirements here and then say that
3:28 we need to use those files finally we could even add them in here. If I said I was using SQLalchemy.
3:38 The first step would be to install it but the second one would actually allow it to add that requirement back in.
3:43 So let's go and do that even but now it's gone from an error to a suggestion and we could say add this over to our requirements file which then puts it
3:55 right there. It was sort of bi directional and super cool.


Talk Python's Mastodon Michael Kennedy's Mastodon