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