Build An Audio AI App Transcripts
Chapter: Appendix
Lecture: Running in VS Code

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In the appendix here, I wanna give you a few tips if you didn't go exactly down the path that I was going, as well as a few extra things
0:11 if you wanna take this project and go further. Okay, the first one that I wanna talk about is how do we run this project in VS Code?
0:21 You know I'm a fan of PyCharm, but I'm also actually a fan of VS Code. I just use them for different purposes.
0:27 And so when I have big projects that need lots of coordination and lots of pieces moving together, it's all day PyCharm for me.
0:35 But there's plenty of times that I would like to use VS Code and I know many people that's their primary editor.
0:41 So I'm gonna show you first how to go and work with VS Code. So over here, I've made a copy of the starter project.
0:48 It doesn't matter what point in time that you're working with here, could be any of them. Okay, so I'm gonna open this up in VS Code.
0:56 In macOS, you can drop it on the icon in the dock. I don't believe that is possible on any other operating system. You can do files, but not folders.
1:05 Okay, now notice we do not have a interpreter for this project. So we could do one of two things.
1:12 We could go up here and we could say create environment, right, use Python to create a virtual environment. I kinda like to have more control over it.
1:20 So let's go, let's do it this way. Let's open up the terminal here and notice I'm in X-Ray podcast. That's the starter project.
1:29 Let's see what's in here. You can see our source directory. This is the top level thing with the requirements. So let's go ahead and do this here.
1:37 PLS is a thing you can pip X install for a nicer LS by the way. So we'll create a virtual environment, Python -m venv, I like to call it venv.
1:48 That's good. And I'm gonna say --prompt is dot. So X-Ray podcast is gonna be the name of the virtual environment.
1:56 And I have an alias to activate virtual environments, you know, dot bin slash activate, et cetera, just AE.
2:04 So now you can see the name is X-Ray podcast. And if we ask which Python or waiter Python, I believe on Windows, I'm one of the, which or where,
2:13 I forget which one is the one that exists or not. Okay, so we could click this, but let's just go over here and we'll pull up the command prompt
2:22 and I'll say select interpreter. Okay, it's recommending the one that is a virtual environment. I'll just choose that. So we should be good to go.
2:31 Why is it not happy with this? And you know, that's the one I picked. Let's just close it and open it again as you know, so often is the fix.
2:39 So there we go, Python 3.12.2, and it's magically happy. Notice that this is not ideal 'cause it doesn't think a lot of these things
2:51 are installed, right? So the next thing to do in our virtual environment, make sure it's active again, right there. Be very careful.
2:59 Pip install -r requirements.txt. And while we're here, let's go ahead and do that spacey download to get the language model working.
3:11 We've already talked about this for the canonicalization of our search indexing. My apologies to GitHub for using up their bandwidth once again.
3:24 All right, we can see many of those errors. Not all of them, but many of them have gone away here. So we should be good to go. Now, how do we run it?
3:33 Well, I click this. Let's see what happens. It's probably not gonna love it. Now is it secrets and static doesn't exist.
3:42 Oh boy, it's running it from the wrong location. And also this is not a great debugging experience. So now that we've got it kind of loaded up,
3:52 let's go over here to our proper debug section. I'm gonna say create a launch JSON, and that's gonna be Python debugger.
4:02 And what I wanna do is, let's say, I do wanna do a fast API. After all, this is fast API. Maybe that's the most appropriate. And it says
4:14 Yes, sort of. So this is pretty good. Look, instead of just running the app, it's gonna run uvicorn, and most importantly, pass in reload,
4:25 and enable Jinja, all those things. Excellent. Let's run it and see what happens. Hmm, there is no main. Huh, what is going on?
4:38 Visual Studio just assumes, of course, everything that you possibly could care about will be right in the root directory,
4:44 'cause why would you have any subfolders? Why would you have organization? Come on, people. So there's zero hint or help here
4:50 about how I would do this, but what I can do is I can basically say, as part of the run, go into this, set that as the working folder,
4:57 and then go from there. So the way we do that is you can come in here and put in your folder, your $workspace folder to your main,
5:04 and this is src in our case. So now if we just rerun it. Awesome, that looks better, doesn't it? Looks a lot better. We've got our traditional startup.
5:19 Look, it's watching for changes. That's great. So if we make changes, it'll automatically reload. You don't have to leave that in there, but you can.
5:26 Uviacorn is running there. You can see it's talking to the database. It looks like everything's working. If we click on it, sure enough, there it is,
5:32 and it should have all of our data. There's our data out of our database. Okay, so that's how we set this up in Visual Studio Code. What did I do?
5:41 I went and opened up the directory or the folder in VS Code. Second, I created, well, you could do this first, probably do it first.
5:50 Create a virtual environment, pip install the requirements into it, then open up the directory so it just discovers it
5:58 as you can see that it did right there, and then I created a launch configuration over on this thing, and I added this little bit of code here
6:10 so that I could look and say, go into that folder and then run main app with reload. All right, so if you feel like you wanna work
6:21 with VS Code, no problem.

Talk Python's Mastodon Michael Kennedy's Mastodon