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


Talk Python's Mastodon Michael Kennedy's Mastodon