For now, you have just run your Python programs directly from the PyCharm IDE here,
with the play button. But what does it do exactly?
So I'm going to do run, I'm going to run the add
two ints here. So add two ints, okay. And it's
going to ask us number one, so I'm going to give
you two, and then number two, three. Two plus
three is equal to five, okay. But actually the
comments, so the first line, what this is. So
you can see we have a long stuff, and at the end,
python.exe. So basically, this is going to run
the python execute table with another file,
okay, with another name, which is basically the
file name. So as you can see, with the complete
path for the add two ints python file that we have here. So python add two ints.py.
This is the command that gets executed in the
terminal. So when you click on play here in
PyCharm, basically the program is executed
just like you would execute it in the terminal.
And this can be very useful to know how to run your Python program from the terminal,
so you can be more independent. You can then
write your code from any text editor or IDE,
like for example in PyCharm, and then run the
program on its own. That's great if you just
want to run an existing program without having to
start the entire IDE. Okay, here you need to start
PyCharm and click on play just to run a very simple
program. So let's see how to run a Python program
from the terminal. I'm going to show you first
for Windows and then for Linux and macOS. Note
that the terminal is usually more used on Linux
and macOS by developers, where basically that's
the default way to control and navigate on your
computer. On Windows, using the terminal is maybe
less common but can still be very useful. And note
here that the commands I'm going to use are the
same on Linux and macOS but are different on
Windows. And let's get started on Windows.
So what you can do on Windows is simply press the
Windows key or just go to the bottom of the screen
and just type cmd or command prompt or terminal or whatever and you just click here.
And this is going to open a terminal. I'm going to zoom in a little bit.
Okay, and you can see that by default you are
in your home directory, so /users/yourname
or your username. To see what you get in there,
you can use the dir command, so dir is going to
give you all the files and folders that you
have in your directory. Here you can see we have
PyCharm project. If you want to go to that PyCharm project, you simply do cd,
py and you can use tab for auto-completion, cd
pycharm project. You can do dir another time and
you can see you have my first project which is
what we are using here. So cd my first project and
then dir another time and you can see we have all
the Python files that we have here on the IDE.
So that's the same thing. And now let's say I want
to run the add to ints.py. I'm going to do Python.
So the Python command simply and then add to int.
I can use tab another time and this is going to run
the script and as you can see here, enter number
one, enter number two and we have the result.
And so this is going to execute the Python program
the exact same way you are going to execute it
when you press play on the PyCharm IDE. And now
let's see how to do that on Linux and Mac OS.
So the instructions here are going to be the same
for Linux and Mac OS. So you have PyCharm with your
programs and etc. You can open a terminal. So open
a terminal also on Mac OS on your applications,
utilities and terminal on Linux. Well Ubuntu for
example, you can directly put the terminal here
or search here for terminal. And then well you are
going to need to find this file here. We want to
launch add to ints. So you can see here the
project is actually on that directory. So home,
PyCharm project, my first project. And we are
actually in the home folder. If you do PWD,
you are in your home folder. So LS, you can see I have PyCharm project and then CD,
PyCharm project. LS, I have my first project, my
first project. LS to list the files. I have my
add to ints.py. I can just do Python 3. So make
sure you have Python 3. You can do Python 3 version
to check that you have Python 3 correctly
installed with a good version. And Python 3,
add to ints.py, I press enter and it's working.
So enter number 1, let's say 4, number 2 is 2,
4 plus 2 is equal to 6. That's working. And for
Mac OS, the commands are also LS and CD and Python
3. Okay, that's going to be the same command.
Congratulations, you can now create Python
programs and run them from the terminal. In the
rest of the course, I'm going to come back to the
PyCharm IDE and run the programs from there. But
on your side, you can decide instead to just run
the programs from the terminal. That's going to be the same.