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