Effective PyCharm Transcripts
Chapter: PyCharm Projects
Lecture: Working with existing projects

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw how in PyCharm to create a new project to create the virtual environment
0:04 and get going. But most of the time what we're doing is working with existing projects that are completely set up.
0:11 We create project and we might work on it for a year or more. Who knows? So if it's already in this list, well then that's easy. You click the button,
0:19 it just pops right back open to the way it was. But if it's a new project that you haven't opened before, let's see how we get that set up.
0:27 I want to start from some existing code that's a little richer and not fiddle around with actually trying to create some structure for you.
0:34 We're just gonna work with an existing project and I'm gonna use the Python for absolute
0:38 beginners course repository for that. So let's go over here and again. I could open it from Git uh VCS for Get but I'll just start from the file
0:48 system that's probably more likely how you're going to do it. Let's go to our desktop again.
0:54 I was gonna clone this into the beginners directory and I'm not even going to create a virtual environment. Now, what's in here Anyway,
1:02 let's open this up. So we've got code which these are all the applications that
1:06 we wrote during that game. So here's a guessing the number of Eminem's in there Here's a rock paper scissors game over here,
1:13 we have like a five or seven way rock paper scissors game some other things tic Tac toe. So I want to open this up,
1:20 I would like to be able to go into these sections and run this bit or maybe jump over and run this and people to see all of those inside of
1:27 PyCharm. So it's more complicated than just say loading up this directory with this one
1:31 file because I'm on Mac, there's a little bit of a bonus that I get that other platforms don't get. I can drag and drop this right on top of
1:42 the PyCharm dock icon and it will open it up. If I was running Windows I was running Linux, I would just hit open and then browse to that folder.
1:50 But on Mac you can actually do a drag drop trick and I will open it up with a bit of a shortcut.
1:56 Now first of all it opened up to read me that it found that the which is kind of cool. So you can see all the read me stuff that's in
2:03 here. It also says we're not really sure what's going on. We took a guess and chose this Jump Start virtual environment And that's not the right
2:13 one. So I'm gonna go over here and you can see interpreter settings. If I open this up that this isn't even valid. It's been deleted is long gone.
2:21 So what I want to do is not use this broken one. I want to add an interpreter.
2:26 We'll click add interpreter and it says we're going to create a new virtual environment for
2:31 you. Perfect. That's exactly what I was hoping what happened. So it's going to be based on 39 and it's going to create it in a
2:37 directory called 'venv'. Which is the common thing that you do in Python
2:41 If I had created one through some other mechanism through 'pipenv' or manually on the command line as part of my work flow.
2:49 When I did a check out there, I could just click this and browse to it. But it's going to create a new one for so let's say okay there right now
2:56 everything is looking better. You can see it's over here on the right virtual environment
2:59 right there. Next up let's look at some of these applications. So if I have this interactive code thing here we can see we've got a guessing
3:06 game. And if we want to run guessing game, we can just run this As we did before. And it says, how many Eminem's are in the jar?
3:12 There are seven. Oh sorry, that's too low. There's 1000. Let's go 200. How about 50 below 75. Let's use some binary tree stuff on it,
3:21 85. Wait, no, that was too high. I've been disqualified. You have to win this game in five rounds.
3:28 Okay, so you can run this pretty straightforward because it's just this single file. Now let's go over to this Chapter6,
3:36 organising code with functions and notice that we've actually got to parts of our applications.
3:43 So we've got our rock paper scissors game here and there's this shared library sub module folder. Directory thing named Space.
3:53 I guess you would call it over here and in there there's a UI helper that can show the header and here we're trying to show the header.
4:00 If I was running all of this from right here, if that was the working directory for PyCharm and Python,
4:06 it would just run when I run this particular file. However, that's not the case. So when we're working with some more complex structure like this,
4:15 we might need to tell PyCharm. Look this part, this subpart this right there,
4:21 that chapter boulder represents its own dedicated application and these pieces are used within it.
4:28 So what we can do is we can mark this directory as what's called a sources root. So we'll come down here and say Mark directory as sources root.
4:36 And that effectively adds that directory to the Python path. So when it looks for shared Libs,
4:42 it's going to know well this is part of my path and here's a thing called shared Libs. I can go find a.
4:46 UI helper in. So let's do that notice there's other things we can Mark as as we could exclude. Like for down here we have our solutions,
4:55 we have some stuff for the read me. Here's a bunch of practice things and notice that PyCharm is warning about duplicated code
5:03 in other places and probably that's actually copies of different variations of this app throughout this
5:09 course. But it could be that it's in these other random areas and we can actually go over here and exclude those from PyCharms.
5:15 Consideration of source code. Notice that's already happening for our virtual environment.
5:19 That's why it's this orange. So we can go over here and mark these as excluded. So that will help.
5:25 Like I said, I think there's still gonna be some reuses these other pieces later but it's fewer now. We can also do things like mark this as a
5:34 resource root. So if I'm in a web app and I want to say '/static/CSS/site.css' if that structure is at the top of this
5:44 resource route, I'll get auto complete in all sorts of information inside of the HTML
5:50 files. If I was in Flask or Django and I had a folder that contained the templates and then in my Django code, my Flask code, I said use this template.
6:00 There's actually a link between the templates that get marked as the template folder and the
6:06 stuff you're doing in Python that'll help you navigate back and understand if they exist or if they're missing and give you all sorts of warnings.
6:12 So there's a bunch of really cool things that you can do here, but probably the most important one to start is this sources route.
6:19 So now I tell PyCharm that this is the application working space and we're gonna
6:24 run this file and it's gonna look in shared Libs or a UI helper that can show a header. Alright, so notice the errors are gone.
6:32 If I under this real quick here un market sources root, it has come back and it's like this is going to crash, it's not gonna work. But again,
6:43 update the Python path, we're good to go. We'd run it and there we go. Here's our little header, see what our little headers doing.
6:51 It says Rock Paper scissor "Function Edition" in right there. And that's running this whole thing as a like a sub application.
6:59 Super important. That's how we get started with existing projects. A couple of things. We created a new interpreter,
7:06 we added a new virtual environment there. We came over here and we said we really want to treat just this section as
7:12 its own inner application. So we mark that as the source route. These things, we don't want to be considered as part of our source code or
7:20 for searching or indexing. So we excluded them. One other thing is we have a couple of things that we could run,
7:26 you know, so I ran the guessing game and I went and did this and I ran the RPS and it did this might get a warning if you want to
7:35 force to restart, which is fine. In this case that leads to the names up here, you might want to change us.
7:42 We can hit edit. And this will we could call this rock paper scissor game
7:47 and maybe give it some extra information like functions because there's other rock paper scissors scissors
7:51 in here. And this could be the 'MM Guessinggame' like that. So now it's a little bit clear.
8:01 Especially if you have the same file like 'app.py' over and over and over again. Which one is Which make sure you give it names.
8:08 And then also notice only exit here. This is just beginners like over here, right click re factor rename. It will say directory or project.
8:18 Project will say 'Beginners Demo Code'. Set up here now, but also more importantly,
8:26 in your little list now, you have some little more descriptive beginner demo code still in the beginner's folder. All right.
8:31 That's how we work with existing projects.


Talk Python's Mastodon Michael Kennedy's Mastodon