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


Talk Python's Mastodon Michael Kennedy's Mastodon