Effective PyCharm Transcripts
Chapter: Packages
Lecture: Opening existing packages

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's begin our exploration of packages by working with an existing package, and what one is more popular than Requests.
0:07 So let's go and just download Requests, git clone it rather and we'll work with that, so do it this way,
0:17 go to our desktop, git clone this, there you have it, nice and quick, and let's go open this in PyCharm,
0:26 so we'll go over here into Requests and before we open it, let's create a virtual environment,
0:30 and we don't want to mess with the Requests for the entire system, maybe just a little isolated thing.
0:35 So let's go over here and create a virtual environment like this and we'll keep that open, we need that again in a second.
0:44 So we can open our Requests, remember file open directory on other OSs, on MacOS you can do it this way which is sweet.
0:51 Down here, we have the various package management files and this is the actual implementation of Requests.
1:00 First of all, let's look at the setup file here and notice there are a lot of requirements that we have to install
1:06 in order to run Requests, especially if we want to do tests on it and things like that,
1:12 so let's go ahead and just click here for the moment, and let that go. Now, this actually can take a while
1:23 especially for pytest http bin so I'm just going to zoom ahead for you. It looks like all the dependencies were set up, so that's great
1:31 now let's just tweak this version a little tiny bit, let's just come over here and we'll say, do a print statement, right at the beginning,
1:41 you would never do this but it will make it entirely obvious like this is our custom version. The idea being we want to test out this package
1:49 maybe we want to make some changes try in another application that we have and then once that's working,
1:57 we could maybe do a PR back to the Request guys and whatnot, so we could also put a variable here, our_var = 42, things like that.
2:07 Now, in order for us to use this outside of this folder in our separate little application in theory would be we need to register Requests with Python,
2:23 so for example, let's go over here, let's activate our virtual environment and let's go up here and run Python and import Requests.
2:36 Notice, we did not see our little message here let's see if it has our_var here, it didn't look like it, right, you just have that stuff right there,
2:49 our_var, no, it has no our_var. This is the Requests package from the system what we want to do is we want to build a work in Python
3:01 and in our little Python app, this is just the REPL, but just as well it could have been I ran my app right here in this environment.
3:09 So what I need to do to make this one the one that I'm working on but for this virtual environment is
3:16 I need to either install it or set it to development mode. So the way you would do that is you would go into Requests and you would say Python setup.py
3:25 develop is probably what you want, when you're working on it or install, if for some reason you want to install it
3:31 and we could come out to the shell and type that, or we could go to PyCharm and come down here and click on tools and notice run setup task.
3:41 Now, I found that sometimes you have to have the directory that contains the setup files selected, not always but sometimes
3:48 so it seems like it didn't matter here so let's try run this, now look what we get we can have install, we could have develop,
3:57 all the cool features that come out of setup tools are right here and what we want is develop,
4:03 we hit this and it actually creates a local symlink, a local install for this one
4:11 and it would have installed the dependencies if I had not clicked that button previously. All right, let's try this again,
4:18 let me get out of Request because if I do it in this folder it's going to find that one.
4:22 So now let's do it again, if I run Python and I say import Requests, boom, this is our custom version
4:29 and I'll say something like print requests.our_var, it's 42, of course it is; and if we had a different one, if we say Python 3 import requests,
4:42 this is not the same virtual environment, it doesn't have that right, it doesn't have this variable. So this is really cool, this setup lets us
4:53 register this package that we got off of github, that could have been something we're working on for ourselves,
4:59 but this existing package, it lets us register it for consumption in this development mode, which is really, really nice.


Talk Python's Mastodon Michael Kennedy's Mastodon