Effective PyCharm (2021 edition) Transcripts
Chapter: PyCharm Projects
Lecture: Creating projects

Login or purchase this course to watch this video and the rest of the course contents.
0:00 so I could just go to PyCharm right here,
0:03 see here's a couple of projects I've already had open and I could just click new
0:07 project or I could even say get from Git Version Control but I want to have
0:13 something come from Git and then work on different projects nested within their and that's not
0:17 gonna work perfectly and I want to have a little bit of structure from the GitHub
0:21 repository. So in general you might just start a new project or open from Git
0:26 but we're going to go to the GitHub repository up here and we're gonna clone this
0:30 onto the desktop. So over the desktop give it some clone cd calling it this
0:38 whole long name, I'm just gonna call it 'course'.
0:41 Perfect, perfect. And then here you can see we have our git: (master).
0:46 I'm gonna actually use a different branch in just a moment every now and then people
0:50 ask me how do you get this prompt?
0:52 This is 'Oh-My-Zsh'(Z shell), absolutely not required but it is kind of handy now
0:56 I don't want to work in this branch here so I'm gonna say 'git check out'.
1:00 now. Normally would do this in PyCharm.
1:01 I want to give you the fresh experience.
1:03 So I got to get things set up to be this fresh experience. Now with
1:07 'Oh-My-Zsh' you can actually hit tab and it will give you all of the
1:11 branches which is awesome, you're gonna just be working with the default branch but as
1:15 I'm updating this course from the previous version.
1:17 I don't want to break it while it's in flight and being created.
1:20 So here we go. Now We can go over to our project folder here and
1:25 notice we've got our demos, we've got projects and there's a bunch of cool stuff
1:29 we're gonna be working on but we're at our first project and in here you can
1:33 see it's effectively empty. So what we're gonna do is we're going to create a
1:37 new project and PyCharm over there.
1:39 We have new project and notice right away we got a bunch of options.
1:43 It suggests maybe it should go here.
1:45 I'm going to propose that maybe somewhere else would be better.
1:49 So I'm gonna drag this folder over here so Mac os can find it, in this
1:55 project here I'd like to create the project.
1:58 That's great. And it's going to create what's called a virtual environment.
2:02 You may be familiar with these if you're not,
2:03 these are really important building blocks to keep our projects separated and clean the ideas instead
2:10 of using the system python, with all the libraries that might be installed,
2:13 we're gonna create basically a copy an isolated empty fresh version of python using a virtual
2:19 environment that then when we install libraries to it's just dedicated to that project.
2:23 So PyCharm is proposing to automatically do that for us and I'll say,
2:27 great, you can do that if we actually had other interpreters,
2:31 maybe we've already created one on the command line or something like that,
2:34 we could browse to it and PyCharm would detect it.
2:36 If it were there following certain conventions like '.ENV' or '.VENV',
2:40 for the name. It would suggest that as well as an option,
2:44 it's also proposing to create a main welcome script,
2:46 which kind of says here's how you run PyCharm.
2:49 We're not going to do that.
2:50 We're going to start fresh. But you could leave that check if you wish.
2:55 Your python is not the only option.
2:57 We have Django, we have Flask, Pyramid,
3:01 we have Scientific stuff. We even have some front and things like React and Angular
3:04 but we're going to stick with our pure python here.
3:07 All right? That should be it.
3:09 We should be able to get going. To notice right away a couple of things.
3:12 It's looking through all the installed libraries and python to figure out the auto complete and
3:17 code corrections and things like that.
3:19 So that takes a moment. But just the first time you open it down here
3:22 you can see which virtual environment is running this is the interpreter.
3:27 And you also see the GitHub branch that we checked out right there.
3:30 That's all cool. And here's our virtual environment that got created and we're not gonna
3:36 need our placeholder so we can go ahead and delete that here.
3:39 We have our empty project. We might as well start by creating a file.
3:42 So let's go over here and create something,
3:45 we'll just call 'hello.py' notice if we go over to the project here,
3:50 let's say new, There's all kinds of new files we can get,
3:52 it's not just python, we could create Jupyter notebooks,
3:55 we could create style sheets, we could create javascript files,
3:58 all sorts of things. Even the funny Gherkin feature file,
4:01 if you wish, we're gonna start by creating a python file and I'll just call
4:07 this Hello because we're working in a directory that has a GIT repository somewhere above it
4:15 is itself a GIT repository. PyCharm says,
4:18 Hey, we can automatically add that to GitHub for you notice it's red over
4:22 here. We're going to dive into the source control features.
4:24 But I'll just so it doesn't bother us.
4:25 I'll say sure you can go ahead and add those files.
4:27 It turned green because now it's staged in Git but not yet committed.
4:32 Okay, so in our Hello World file,
4:35 you know the drill, we're going to do something like print.
4:37 Hello World as we type it,
4:41 all sorts of help. Very nice.
4:43 Often the Hello World people perceive this as how do I create the most minimalistic type
4:49 of application that I can, but that's not really the purpose of Hello World.
4:53 The purpose of Hello World is to prove that the system is set up to run
4:57 some kind of application in this case the python app.
5:00 So it'll prove that our virtual environment set up and that we can,
5:03 you know, click this button up here maybe somehow and make it run.
5:07 So how are we going to do that?
5:09 Well, we'd like to click this looks like a run thing you hover over.
5:13 It says run but obviously it's great out.
5:15 It's not going to do anything because we could have many python files.
5:18 Open PyCharm doesn't know what to do with them.
5:21 What we can do is we can right click over here and we can pick any
5:24 of these options, run debug or even we could run with code coverage.
5:28 We could profile it, we could do concurrency analysis.
5:32 All that seems way overkill for Hello World.
5:35 So we're just going to run it like this.
5:38 Hello World. Perfect there. You have it.
5:40 You can see that it ran our file here,
5:43 way out at the end And it ran it using the Python,
5:46 out of our virtual environment. That PyCharm created not the system one.
5:51 And by the way, if you need to run outside of PyCharm,
5:53 just copy that path. That whole thing there and drop into a command prompt or
5:57 terminal and boom, off you go.
6:00 All right. So now that we've run it,
6:02 we've right, clicked and said run this is generated what's called a run configuration up
6:06 here now says Hello, we can change the name.
6:08 Now, I have a presentation assistant installed,
6:11 which I mentioned before in the previous chapter.
6:13 But if I click this, it's going to actually pop up this green box that
6:17 says run Hello via CTRL+R on your current key map or if you're on windows
6:22 or Linux, you can press 'shift + F10' depending on the key map you pick
6:26 sometimes that's F5. So if I hit that hot key again you can see
6:29 right here. It just keeps running it.
6:31 But this is something you really want to pay attention to as we work with different
6:34 parts of PyCharm, it will help you learn what the various commands are being
6:39 called. And sometimes it's not entirely obvious.
6:42 Sometimes, like if I say wanted to reformat this code here,
6:46 I can go over to code and I could click reformat or I could just hit
6:50 command 'ALT+L'. So sometimes I'll do something like this.
6:53 You know what happened? Just look at the green box.
6:56 That's what's going on there. One other thing to look at here is we don't
7:00 need just the one file. Right.
7:02 One of the beauties of PyCharm is it understands many many files.
7:05 We could have another file and here we could have something like an other method.
7:10 It takes some text and I'll print,
7:17 print out whatever the other text is.
7:19 Now there's a little squiggly here meaning that the formatting is a little bit off so
7:22 we'll just let PyCharm fix it.
7:24 So it doesn't look like there's some kind of air.
7:27 All right. But of course what we're running is our Hello World app over there
7:30 All right. Well, that's the quick introduction to getting started.
7:34 Main takeaways. Virtual environment. Very important if you're in a GitHub repository or some
7:41 other kind of source control, it likely will discover that and automatically integrate that we
7:46 didn't do anything. This just happened automatically.
7:49 When we want to run a file,
7:51 we have to go over here and say first create some kind of run configuration so
7:57 that we can then click here.
7:58 Hit 'CTRL+R' to run it.
8:00 That's it. We've written a program with PyCharm.
8:04 Well, I would be too proud of this thing, but still pretty cool!!.