Consuming HTTP Services in Python Transcripts
Chapter: Initial HTTP GET requests with the requests package
Lecture: A clean environment for our course

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Now, we are going to need to install some packages, during this class, in particular we need to install Requests,
0:07 we are going to need to install Beautiful Soup, and some of the other foundational or dependent packages there. Now, one thing we could do is
0:14 we could say pip install requests or something to this effect, however, if we do, this is going to modify our global system,
0:20 and there is a couple of drawbacks to that, we don't want to modify our global system because it requires us to run these installers as admin,
0:30 and this is kind of running arbitrary code off the internet as admin, not super recommended,
0:33 it also means that we are going to use the same version of the library across every project we run, on our computer,
0:39 so maybe we want to use the newest request for this, but some other projects it's old and it needs to use an older request
0:45 because there is some kind of change, how do you manage those two environments? So the answer of course is to use virtual environments,
0:51 so let's just ask which pip or which pip 3 is really what we want, so we want to say, see this is obviously the global one,
0:57 and if we ask it what is installed, you'll see that there is a bunch of stuff installed, so, let's actually create what is called a virtual environment
1:04 that we'll use for the rest of this class, so I am in a directory called /pyhton/environments,
1:09 there is a lot of conventions around this actually, there is different locations for different people,
1:14 sometimes you put it in your project directory, sometimes you put these outside, I am going to put them in this folder in my user profile.
1:19 In Python 3, there is a built in way to create a virtual directory, so we can say Python 3, now on Windows, there is no Python 3 just be aware,
1:26 you just have to have the path to Python 3 versus Python 2. So that is a little tricky, but on Linux and OS 10 we can say Python 3
1:33 and that is pretty straightforward, and we want to run the module, venv, and we want to give it some sort of path,
1:40 so let's say we'll go to consuming services venv. Now, this will totally work, however, just one word of caution here- if your are on a Mac,
1:48 and you are going to use PyCharm, both of these things need to be true, if you are on a Mac and you are going to use PyCharm,
1:56 there is a problem with PyCharm understanding the type of basically following the symlinks too far when you set up a virtual directory this way,
2:04 and so what you need to do for the time being, is add a copies flag here to say don't create symlinks, create just a copy of the Python file
2:14 that we can link to directly in this environment. So, because I am going to be using PyCharm,
2:20 I am going to put --copies and I am on a Mac, it's up to you, but, I recommend doing the --copies for the time being.
2:28 Okay, great, we've created it, how does this change our pip story? Not at all, because notice my prompt, it still says Mac Book Pro,
2:35 just standard prompt there, so what we need to do is we need to activate this, we need to basically change this individual shell temporarily
2:43 to know only about that Python, so I can come over here and say . (dot) so apply this what I am about to do to this shell,
2:51 and I am going to run ./consuming_svc_env/bin/activate on Windows, you don't need the dot and this is activate.patch.
2:57 Notice, my prompt changed, if I ask which pip, now it's this one, again, if I ask which Python, it's now this one from this environment.
3:05 Great. So, most importantly, what we are after, we were asking for a clean environment,
3:10 and here we have a brand new fresh clean virtual environment, with pip and setup tools.
3:14 So now we can start installing things that we are going to use for this project, here, so let's say pip install requests.
3:23 And it either uses a cash version or downloads it from the internet, and then installs it,
3:30 and now if we ask pip list we can see, yeey, requests is installed,
3:34 so let's just verify that everything is hanging together, we'll do a quick little thing here,
3:38 we can come over and import requests, and because that didn't break, things are looking good, and then we can just make sure
3:45 that there is actually something reasonable here, there we go. So we've got cookies, sessions, get, post, those kinds of things.
3:53 Alright, so it looks like requests was installed successfully. Now we are ready to use this environment,
4:00 this clean environment which does not require admin rights on the machine and is just dedicated to our little project here,
4:05 we can use this clean environment for the rest of the class.


Talk Python's Mastodon Michael Kennedy's Mastodon