Effective PyCharm (2021 edition) Transcripts
Chapter: PyCharm Projects
Lecture: Using the EAP version
0:00 I spent some time telling you how cool PyCharm is,
0:02 but I think it's time that we actually get down to business and write some code
0:05 and work with some python projects.
0:07 Now before I start PyCharm
0:09 I want to point out one thing really quickly here.
0:12 So remember I recommended that used the JetBrains toolbox to install PyCharm because it keeps
0:17 it up to date. For example,
0:18 if I want Android Studio, I just click that button,
0:20 I have it and it keeps itself up to date.
0:23 So you can actually see three versions of PyCharm over here.
0:26 Even though we were told there were two there's an EAP early access program
0:31 that I'm going to be using because there are some cosmetic changes that are coming in
0:36 PyCharm. I've been talking to the PyCharm team that I got to be
0:39 aware that there's some changes coming.
0:40 I want to make sure that you incorporate that into the new course.
0:43 So I'm going to be using this EAP version but I recommend you just
0:47 use the main stable dev version unless you feel like living on the cutting edge with
0:52 that out of the way, let's get started.
0:54 So I could just go to PyCharm right here.
0:57 You see, here's a couple of projects I've already had open and I could just
1:00 click new project or I could even say get from get version control but I want
1:07 to have something come from get and then work on different projects nested within their and
1:11 that's not gonna work perfectly. I'm going to have a little bit of structure from
1:14 the Git repository. So in general you might just start a new project or open
1:18 from get but we're gonna go to the GitHub repository up here and we're gonna clone
1:22 this onto the desktop. No over the desktop.
1:27 Give it some clone instead of calling it this whole long name,
1:31 I'm just going to call it course.
1:34 Perfect, perfect. And then here you can see we have our Get master.
1:39 I'm gonna actually use a different branch in just a moment.
1:42 Every now and then people ask me,
1:43 how do you get this prompt?
1:44 This is oh-my-zsh, absolutely not required.
1:47 But it is kind of handy now,
1:49 I don't want to work in this branch here.
1:50 So I'm gonna say get check out now.
1:52 Normally would do this in PyCharm but I want to give you the fresh experience
1:55 So I got to get things set up to be this fresh experience.
1:58 Now with oh-my-zsh you can actually hit tab and it will give you
2:02 all of the branches which is awesome.
2:04 You're gonna just be working with the default branch.
2:06 But as I'm updating this course from the previous version,
2:09 I don't want to break it while it's in flight and being created.
2:12 So here we go. Now we can go over to our project folder here and
2:18 notice we've got our demos, we've got projects and there's a bunch of cool stuff
2:21 we're gonna be working on but we're at our first project and in here you can
2:25 see it's effectively empty. So what we're gonna do is we're going to create a
2:29 new project and PyCharm over there.
2:32 We have new project and notice right away we got a bunch of options.
2:36 It suggests maybe it should go here.
2:37 I'm going to propose that maybe somewhere else would be better.
2:41 So I'm gonna drag this folder over here so Mac os can find it in this
2:48 project here. I'd like to create the project.
2:51 That's great. And it's going to create what's called a virtual environment.
2:54 You may be familiar with these if you're not.
2:56 These are really important building blocks to keep our projects separated and clean the ideas instead
3:02 of using the system python with all the libraries that might be installed.
3:05 We're going to create basically a copy an isolated empty fresh version of python using a
3:11 virtual environment that then when we install libraries to it's just dedicated to that project.
3:16 So, PyCharm is proposing to automatically do that for us and I'll say,
3:20 great, you can do that if we actually had other interpreters,
3:23 maybe we've already created one on the command line or something like that.
3:26 We could browse to it and PyCharm would detect it if it were there following
3:30 certain conventions like .env or .venv for the name.
3:34 It would suggest that as well as an option,
3:36 it's also proposing to create a main welcome script,
3:38 which kind of says, here's how you run PyCharm.
3:42 We're not going to do that.
3:43 We're going to start fresh. But you could leave that check if you wish.
3:47 Your python is not the only option.
3:48 We have jingo, we have flask pyramid,
3:52 we have scientific stuff, we even have some front and things like react and angular
3:55 but we're going to stick with our pure python.
3:58 You all right? That should be it.
4:00 We should be able to get going.
4:02 I was saying there's this placeholder file in there,
4:04 which I needed to make get create that structure.
4:07 Uh so I'll just say create from this,
4:09 but it doesn't really matter which we choose.
4:12 You notice right away a couple of things.
4:14 It's looking through all the installed libraries and python to figure out the auto complete and
4:19 code corrections and things like that.
4:20 So that takes a moment. But just the first time you open it down here
4:24 you can see which virtual environment is running this is the interpreter and you also
4:29 see the git branch that we checked out right there.
4:32 That's all cool. And here's our virtual environment that got created and we're not gonna
4:37 need our placeholder. So we can go ahead and delete that.
4:40 So here we have our empty project.
4:42 We might as well start by creating a file if we go over to the project
4:46 here, let's say new. There's all kinds of new files we can get,
4:49 it's not just python, we could create jupiter notebooks,
4:55 all sorts of things. Even the funny Gherkin feature file if you wish,
5:00 we're going to start by creating a python file and I'll just call this Hello because
5:05 we're working in a directory that has a Git repository somewhere above it.
5:10 Is itself a Git repository. PyCharm says,
5:13 hey, we can automatically add that to get up for you notice it's red over
5:17 here, we're going to dive into the source control features.
5:19 But I'll just so it doesn't bother us.
5:20 I'll say sure you can go ahead and add those files.
5:22 It turned green because now it's staged and get but not yet committed.
5:28 Okay, so in our Hello World file,
5:30 you know the drill, we're going to do something like print.
5:32 Hello World as we type it,
5:36 all sorts of help. Very nice.
5:40 Often the Hello World people perceive this as how do I create the most minimalistic type
5:45 of application that I can, but that's not really the purpose of Hello World.
5:50 The purpose of Hello World is to prove that the system is set up to run
5:53 some kind of application in this case,
5:55 the python app. So it'll prove that our virtual environment set up and that we
5:59 can, you know, click this button up here maybe somehow and make it run
6:03 So how are we going to do that?
6:05 We'd like to click this looks like a run thing you hover over.
6:07 It says run but obviously it's great out.
6:10 It's not going to do anything because we could have many python files.
6:13 Open empire charm doesn't know what to do with them.
6:15 What we can do is we can right click over here and we can pick any
6:19 of these options. Run debug or even we could run with code coverage.
6:23 We could profile it, we could do concurrency analysis.
6:26 All that seems way overkill for Hello world.
6:29 So we're just going to run it like this.
6:32 The world. Perfect there. You have it,
6:34 you can see that it ran our file here way out at the end and it
6:39 ran it using the python, out of our virtual environment.
6:42 That PyCharm created not the system one.
6:45 And by the way, if you need to run outside of price I'm just copy
6:48 that path, that whole thing there and drop into a command prompt or terminal and
6:52 boom off you go. So now that we've run it,
6:56 we right clicked and said run this is generated what's called a run configuration up here
7:00 now it says hello, we can change the name but we can just click this
7:04 button over and over and over to run it now I have presentation assistant installed
7:08 which I mentioned before in the previous chapter but if I click this it's going
7:12 to actually pop up this green box that says run Hello via control are on your
7:17 current key map or if you're on windows relating.
7:20 So you can press SHIFT-F10 depending on the key map you pick.
7:23 Sometimes that's F5. So if I hit that hot key again you can see
7:27 right here. It just keeps running it.
7:28 But this is something you really want to pay attention to as we work with different
7:32 parts of PyCharm, it will help you learn what the various commands are being
7:37 called. And sometimes like if I say wanted to reformat this code here,
7:41 I could come over to code and I could click reformat or I could just hit
7:45 CMD-ALT-L. So sometimes I'll do something like this.
7:48 You know what happened? Just look at the green box,
7:51 that's what's going on there. One other thing to look at here is we don't
7:57 need just the one file. Right.
7:59 One of the beauties of PyCharm is it understands many many files.
8:02 We could have another file and here we could have something like an other method.
8:07 It takes some text and I'll print print out whatever the other text is.
8:17 Now there's a little squiggly here meaning that the formatting is a little bit off so
8:21 we'll just let PyCharm fix it.
8:23 So it doesn't look like there's some kind of error.
8:25 Right. But of course what we're running is our Hello World app over there.
8:29 All right, well, that's the quick introduction to getting started.
8:33 Main takeaways. Virtual environment. Very important if you're in a git repository or
8:39 some other kind of source control,
8:41 it likely will discover that and automatically integrate that.
8:44 Like we didn't do anything. This just happened automatically.
8:48 When we want to run a file,
8:50 we have to go over here and say first create some kind of run configuration so
8:55 that we can then click here.
8:57 Hit control are to run it.
9:00 That's it. We've written a program with PyCharm.
9:03 Well, I would be too proud of this thing,