Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
PyCharm is a great IDE, or Integrated Development Environment, from JetBrains for writing Python. Let's explore how to get and install PyCharm and some of its great features.
Get PyCharm from its website. Be sure to check out the educational versions, too.
The PyCharm documentation is super-handy.
Hi, Kenneth here.
0:05
For almost all of the Python, Flask, and
0:06
Django we've done here at Treehouse,
you've used Workspaces.
0:08
Workspaces is an amazing tool but you
probably don't want to use it when you're
0:12
writing code on your own computer or
at work.
0:16
You'd probably rather use a text editor or
an IDE Text editors and
0:17
IDEs provide some very handy tools like
code coloring, automatic code cleaning and
0:22
syntax error checking and much more.
0:27
In this workshop, I wanna show you
some of the features of a great
0:30
Python IDE from JetBrains named PyCharm.
0:32
An IDE, which stands for
0:36
Integrated Development Environment, is
a programming tool that encapsulates a lot
0:37
of very useful tools like code editors,
GIT integration, and
0:41
debugging tools into one handy package,
and PyCharm is no exception.
0:45
PyCharm provides all of the features
that I mentioned before and much more.
0:50
Like automated refactoring, coverage
supports for your tests, and solid
0:54
code suggestions when you're using Django
Pyramid, Flask, and other frameworks.
0:58
I won't be able to show you
everything that PyCharm offers.
1:03
That would simply take way too much time,
and besides that,
1:06
Jet Brains offers some wonderful
documentation that you can refer to for
1:09
things that I don't get to,
or that you forget.
1:12
So head over to Jetbrains.com,
download the free trial of PyCharm, and
1:16
let's get started learning
about this very handy idea.
1:20
Okay, so this is the PyCharm website
from JetBrains, and you can come here,
1:24
read through the docs and demos,
the features, all that kind of stuff, but
1:30
what you're ultimately looking for
is this download button or
1:33
this Get PyCharm Now button,
same difference, and
1:37
you can download
the Community Edition if you want.
1:41
It's free.
1:43
It'll do most of the stuff that I'm
gonna show you in this workshop.
1:44
There are some things that it won't do
that only the professional version does.
1:49
Now the cool thing is, if you get the
professional version, if you wanna get it
1:54
and you go to the buy link, there
are ways to get it for less or for free.
1:57
So if you're buying it for yourself, it's
only $90 a year which is fairly cheap.
2:02
I know it's not insanely cheap, but
it's fairly cheap, and then there's
2:08
also some discounted ones for education,
and training so that the teachers.
2:12
As you're a student,
if you email in to Jet Brains,
2:16
they might give you This qualification.
2:19
I'm not sure of they will or not,
but it's worth asking about, right?
2:22
And if not,
2:26
then there's definitely the educational
version that you should be able to use.
2:27
Alright, so you'll get PyCharm, you'll
get it installed, you'll launch it and
2:31
it'll look something like this.
2:34
So, I want to create a new project, and
2:36
I want it to be a Python project,
but I don't want it to be 2.7.
2:41
I installed 3.5, and
if you haven't done that yet,
2:45
you can go check out
the local Python workshop.
2:48
So, I need to tell this
where this interpreter is.
2:53
Now, you only need to do this one time,
but you see these ellipses there,
2:55
you're going to click on those,
and you're going to say Add Local.
2:59
So you're gonna add in a local python.
3:03
Now it's not at user/bin/python for me.
3:06
It is at another directory,
which I don't remember.
3:09
So, let's do this.
3:15
Terminal, which python3.
3:18
So it is at this Directory.
3:20
So I'm going to copy that.
3:24
Okay, here we go.
3:30
So, paste that in, and it finds it.
3:31
Awesome, and I say okay, and
3:35
it's going to update these skeletons
which really this is just like,
3:37
how do we, what are all our bits and
pieces of Python three.
3:43
So I'm going to do that and that's
cool and it creates this directory for
3:46
you called PyCharm Projects and so
I'm just going to put a name in here and
3:49
I'm just call PyCharm Workshop,
so that's what we're doing and
3:53
I'm going to hit create And boom.
3:58
So we have our workshop.
4:02
So we've got a project's files thing here,
which there's nothing listed in yet
4:05
except for this idea,
which are configuration files for idea.
4:10
Which is the ide that Python was based on.
4:16
It's based on idea.
4:19
So you'll see the dot idea folder or you
can click on project and you'll see this,
4:23
and this'll show you like
external libraries, so
4:27
here's Python's libraries and
all that stuff.
4:29
Most of the time you're not
going to care what's in there,
4:32
you'll only care what's in here.
4:34
So feel free to look at the project files
view instead, it's a little bit nicer.
4:37
So we added an interpreter and
we started a new project.
4:41
So let's start a new script.
4:44
I'm gonna here on PyCharmWorkshop.
4:47
I'm gonna hit command n, and
4:48
you're gonna see this thing
right here the screen thing.
4:51
I have that turned on for you.
4:53
You won't have that on your
own version of PyCharms but
4:56
don't worry about that
popping up all the time.
4:58
So we can say a new file, or we can
specifically say a new Python file, and
5:01
then since I have the pro version,
I can do HTML files, JavaScript files,
5:05
stuff like that.
5:09
So I'm just gonna go ahead and hit file,
because it doesn't really matter, and
5:10
we're gonna do a new file name.
5:14
So I'm just gonna say first.py,
this is my first Python file.
5:15
We're here.
5:20
All right, so
a couple of things we wanna to turn on.
5:22
Let's go to view and active editor, and
5:24
we wanted to show white space because
white space is important on Python, and we
5:28
wanted to show line numbers because line
numbers are important in every language.
5:32
You also see that we had these
indent guide turn on, and
5:38
you will see that in just a minute.
5:40
So let's make a function 'cause this is Python,
and so all these IDs,
5:42
one of the things they offer is
something that's called intellesense or
5:47
codecompletion or there's probably
several other names for it.
5:50
If I do d e,
you see this window that pops up.
5:54
This window is PyCharm trying to
figure out what I want to do So
5:57
if I just have a d there's a whole lot of
options because there's a lot of things
6:03
that have d in them, but
it knows that def is the most likely.
6:07
I probably wanna type def.
6:11
So I can actually just hit tab and
it just puts that in for me.
6:13
I can also do dot,
that doesn't do anything.
6:17
In some IDEs, dot does the completion.
6:20
In PyCharm it does not But I can also
just hit enter and that'll put it in.
6:22
So def and then we'll put in a name for
our function, so
6:28
let's just say say_hello and
we'll require a (name) argument,
6:32
and now we're inside of our function,
and so you can see so
6:38
we've got our indentation stuff here and
these right here lets us do code folding.
6:41
We'll talk about that in just a minute.
6:46
So first of all let's just print out,
actually I want to show you that too.
6:48
If I type in print, see how it has this
objects, sep, end, file, whatever?
6:53
If I do print and I just sit here for
a minute it starts to show this stuff, and
6:58
I could put in these mini objects as I
want separators and things like that.
7:02
So I'm gonna put in Howdy and
7:05
these two bits and I close my string,
and then it starts pulling up.
7:10
These are the things
that all work on strings.
7:16
See how they have str over here.
7:18
This shows the class that they work on.
7:20
I want format, so I gonna do fo,
and it's like, he wants format.
7:22
So it pops that up.
7:27
I can press enter and format comes up.
7:28
Format just expects args and kwargs,
so we need to pass those in.
7:31
So I'm gonna put in the name variable,
and,
7:35
again it doesn't just work with Python.
7:37
I type N and it know that it has
a parameter called Python or
7:40
called name rather, and so I can just
press ENTER and it'll put name in for me.
7:44
So if I wanna be really lazy and
if I don't want to do a lot of typing.
7:49
PyCharm goes a long way in that.
7:54
So let's add in some more stuff here.
7:57
First of all I wanna
show this code folding.
7:59
If I click on either one of these
minus signs, then it folds up, and
8:01
you can see it as an ellipsis here and
it's got a plus sign here.
8:05
Now if I hover over the ellipsis,
it'll show me the bottom of the function.
8:08
Let's add in a little bit more stuff here,
and
8:12
let's actually break this
out a little bit, and
8:15
we'll pretend that we don't,
we've got a lot more code than we do.
8:20
So if we close this up, and
then it'll show me my whole thing, and
8:24
if I open it back up,
You see this vertical lines running here?
8:29
Those are my indentation guides.
8:33
Now sometimes the indentation guides and
8:35
the white spaces kind of conflict, and
you might wanna turn one on or the other.
8:38
I kinda like having them both on.
8:44
I don't mind the visual noise,
but that's gonna be up to you.
8:45
So now let's actually use our function.
8:48
So we'll say if and again I do the I,
starts to give me a bunch of stuff, right?
8:51
But if and
then I need to do something for my if.
8:57
Now I haven't done anything yet.
9:02
You notice there's these squigglies,
the red squigglies.
9:03
That means something is wrong and
9:06
if you look at those red
squigglies on the file name.
9:07
In both places it shows up.
9:10
So there's something wrong in this file,
9:11
and there's even a red line right
over here and it's saying, okay.
9:13
I'm either expecting an indent or
an expression.
9:18
I don't know which thing I'm expecting,
and
9:20
up here is another warning telling us
that there's a couple of errors found.
9:23
So let's go ahead and do this.
9:27
So if.
9:28
Name is equal to dunder main.
9:30
Then we want to do, say hello,
and we'll pass in Kenneth.
9:35
So I saved everything, command S.
9:43
This whole thing that pops up here,
9:46
these are like options that PyCharm
thinks you might want to do.
9:47
So you can click on that.
9:52
You can choose to reformat the file.
9:53
You can do a lot of other stuff.
9:55
Let's see what happens if
we choose reformat file.
9:56
So it made it look a little bit nicer,
kinda cleaned up a couple of things.
9:59
It put more spaces in right here.
10:02
Let's command + Z See
there's only one space there.
10:04
So there's only one space,
I can actually come up here to a code,
10:09
that's where it is and choose reformat
code and it'll do that for me.
10:13
Where this is really cool is
if we did something like this.
10:19
So, read and say two spaces right there,
and then I can come up to Code and
10:22
reformat Code, and
it knows how I like Python code,
10:26
and knows Python code is four spaces,
things like that.
10:30
So it'll automatically reformat that for
me.
10:33
It's a handy thing to
do from time to time.
10:35
So let's save this, and
now, let's run this file.
10:37
I need to go out to my terminal, right?
10:42
No, I don't.
10:45
That's the cool thing.
10:46
I can go here to run, and I can choose
this run with the three ellipses.
10:47
I only have to do this the first time.
10:51
I choose that and
these are my run configurations.
10:54
So I can make a new configuration,
or I can let Pi term do what it
10:56
thinks I wanna do which is to run
first which is what I wanna do.
11:00
So I'm gonna run it, and this right here.
11:06
So, we have multiple windows
at the bottom, here.
11:08
This window right here is window
number four, and it's called run, and
11:10
the out put was Howdy, Kenneth.
11:14
You can see here, it ran python three,
and it ran first.pie.
11:15
It ran, it printed out Howdy, Kenneth,
and finished with an exit code of zero.
11:21
So this is nice for a quick way to just
run your program, and this works for
11:26
really long programs,
11:30
really short programs, whatever kind
of program you are working on, and
11:31
you can either click this button
here that kinda looks like it's
11:35
pointing at a thermometer, or you can just
click run and it'll hide that for you.
11:38
If your process was really long running,
11:44
you would have a stop sign over
here too that you could hit stop.
11:46
All right.
11:48
So let's say that I want to make my
program a little bit more random,
11:51
and I want to get a number, and I
11:56
want to do random.randint(1, 10000), and
12:02
then I want to say Howdie Kenneth and
then I want to print your hour
12:07
visitor, and
I'm gonna format that with numb.
12:12
So I dont have random imported.
12:18
See how it has this underline?
12:21
The squigglies again?
12:23
So it doesn't know what to do there.
12:25
So if I hit option enter on this line it
doesn't know what to do, but if I'm on
12:26
this line and I hit option enter,
it's like okay how do we figure this out?
12:30
So I can tell it to just to ignore
it like, this stuff is all good,
12:34
don't worry about this stuff.
12:39
I can do that in two different places,
or I can rename it.
12:40
Maybe I used the wrong name.
12:45
I didn't want to use random,
I wanted to use some of the library, or
12:46
I can tell it to import this name.
12:49
So I'm going to see if they're the same,
and
12:51
then I get to pick where
I want to import it from.
12:52
I can import it from random, or
12:54
I can try to import it from random.random,
which isn't going to work.
12:56
So let's import from the python library,
random.
13:00
Press Return and
now import random is up here.
13:03
So this is just a holdover.
13:07
We don't need that any more.
13:09
So we'll save again, and so now,
we don't need to go to Run and
13:11
then the one with the ellipses.
13:15
We can just say run first,
we can hit Ctrl+R,
13:17
or we can just click this arrow up here.
13:20
So I'm the three thousand and
sixtieth visitor, cool.
13:24
Let's run it again to see
what number I get that time.
13:27
Thirty eight o'nine.
13:29
Getting a lot of numbers
close to each other,
13:31
and every time I click this the play
arrow I just get it run again.
13:33
So that's pretty nice.
13:39
Even nicer is this kind of thing.
13:41
I'm like I dont 'like that anymore,
I'm gonna take that out and
13:43
I'm not gonna get a random number anymore.
13:47
So let's save.
13:51
First of all, two things happened.
13:52
I have input random is now grayed
out it's not being used anymore, and
13:54
I'm not using it, so
I should get rid of it.
13:59
So if I go to code and
I choose optimize imports, or on a Mac,
14:01
control option O, then the import is taken
out, because I'm not using it anymore,
14:06
and if I save and I run, everything
works just like it did the first time.
14:12
So, being able to create
a new interpreter.
14:17
Being able to use IntelliSense to
figure out what code I want to put
14:20
it because maybe I don't remember all
these things, and I don't remember all
14:23
the arguments to these things, and then
being able to let it handle my imports for
14:26
me, whether that's adding new ones or
taking ones out, is really really useful.
14:31
You need to sign up for Treehouse in order to download course files.
Sign up