Python for the .NET developer Transcripts
Chapter: Database access and ORMs in Python
Lecture: Running our Flask app outside PyCharm

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Running our web app in PyCharm makes it a breeze.
0:03 Click here, look it's looking perfect.
0:06 However, watch what happens if we try to run this
0:09 outside of PyCharm. I'm going to copy this path here.
0:14 I'm going to go over to it.
0:16 Now, it's super important to realize
0:17 our virtual environment is not active yet
0:20 so we need to do that. So we have to say, dot, go back a directory
0:24 say . venv/bin/activate or on Windows, forget the dot
0:28 just venv\scripts\activate. But the outcome should be this.
0:33 Alright, let's go back to our ch08_db.
0:37 So here's the Guitary thing, let's go in there
0:39 and let's just run it.
0:40 And the easiest way to run it is to say
0:43 python app.py. Wait a minute, no module named guitary?
0:48 Weird, okay, what if I go up a directory
0:50 and I say python guitary/app.py?
0:54 Well what's going on here, well what is going on
0:57 is that with Python
1:01 these directories are basically treated like name spaces.
1:04 Where our app.py is relative to the other stuff
1:07 it's a little freaked out.
1:09 There's ways we could fix this.
1:10 We could set it up as a package
1:12 rather than as just a set of files which would fix it
1:15 but that's another thing that we'd have to worry about.
1:18 It turns out fixing this is super easy
1:21 we can just go up here to the top, copy a couple of lines
1:23 because they don't really matter. So go to anywhere before the first Guitary
1:27 and I'll just do it at the very top here.
1:29 We can do a little bit of messing with the path
1:32 basically add the top level directory.
1:36 So for, here, and go up one directory
1:40 and add that to the path. Actually go up one directory
1:43 and add that to the path. So guitary/app now exists.
1:47 You're going to get some warnings here
1:48 that say, you're not supposed to put this at the top
1:51 but obviously if you don't put it at the top
1:53 it's going to crash.
1:54 So, I'd rather break the convention and have it work
1:57 than not break the convention and have it fail right?
1:59 That seems silly. So now, here we are
2:02 if we, lets' just go in here doesn't really matter.
2:04 At this point we just say python app.py
2:08 Boom. It's off and running, except for
2:11 it's already running over here
2:12 it's can't share that address.
2:13 So try it one more time.
2:16 Beautiful, and let's just make sure things work.
2:19 Yes, they do.
2:21 Still talking to our database, just like you'd expect.
2:25 Right here you can see a bunch of stuff coming back.
2:27 Uh yeah, it looks like we need to do little cleanup
2:29 on one of our SQLite objects.
2:31 But none the less, everything is
2:33 other than that little detail there, which I'll look into
2:35 it looks like we got it running just fine.