1 00:00:00,000 --> 00:00:06,000 For now, you have just run your Python programs directly from the PyCharm IDE here, 2 00:00:06,001 --> 00:00:09,560 with the play button. But what does it do exactly? 3 00:00:09,572 --> 00:00:13,000 So I'm going to do run, I'm going to run the add 4 00:00:13,001 --> 00:00:16,903 two ints here. So add two ints, okay. And it's 5 00:00:16,915 --> 00:00:21,000 going to ask us number one, so I'm going to give 6 00:00:21,001 --> 00:00:24,450 you two, and then number two, three. Two plus 7 00:00:24,462 --> 00:00:28,000 three is equal to five, okay. But actually the 8 00:00:28,001 --> 00:00:30,861 comments, so the first line, what this is. So 9 00:00:30,873 --> 00:00:34,000 you can see we have a long stuff, and at the end, 10 00:00:34,001 --> 00:00:38,640 python.exe. So basically, this is going to run 11 00:00:38,652 --> 00:00:43,000 the python execute table with another file, 12 00:00:43,001 --> 00:00:45,489 okay, with another name, which is basically the 13 00:00:45,501 --> 00:00:48,000 file name. So as you can see, with the complete 14 00:00:48,001 --> 00:00:57,000 path for the add two ints python file that we have here. So python add two ints.py. 15 00:00:58,000 --> 00:01:00,545 This is the command that gets executed in the 16 00:01:00,557 --> 00:01:03,000 terminal. So when you click on play here in 17 00:01:03,001 --> 00:01:06,292 PyCharm, basically the program is executed 18 00:01:06,304 --> 00:01:10,000 just like you would execute it in the terminal. 19 00:01:10,001 --> 00:01:15,000 And this can be very useful to know how to run your Python program from the terminal, 20 00:01:15,001 --> 00:01:17,989 so you can be more independent. You can then 21 00:01:18,001 --> 00:01:21,000 write your code from any text editor or IDE, 22 00:01:21,001 --> 00:01:24,022 like for example in PyCharm, and then run the 23 00:01:24,034 --> 00:01:27,000 program on its own. That's great if you just 24 00:01:27,001 --> 00:01:29,958 want to run an existing program without having to 25 00:01:29,970 --> 00:01:33,000 start the entire IDE. Okay, here you need to start 26 00:01:33,001 --> 00:01:36,048 PyCharm and click on play just to run a very simple 27 00:01:36,060 --> 00:01:39,000 program. So let's see how to run a Python program 28 00:01:39,001 --> 00:01:41,989 from the terminal. I'm going to show you first 29 00:01:42,001 --> 00:01:45,000 for Windows and then for Linux and macOS. Note 30 00:01:45,001 --> 00:01:48,489 that the terminal is usually more used on Linux 31 00:01:48,501 --> 00:01:52,000 and macOS by developers, where basically that's 32 00:01:52,001 --> 00:01:54,926 the default way to control and navigate on your 33 00:01:54,938 --> 00:01:58,000 computer. On Windows, using the terminal is maybe 34 00:01:58,001 --> 00:02:01,081 less common but can still be very useful. And note 35 00:02:01,093 --> 00:02:04,000 here that the commands I'm going to use are the 36 00:02:04,001 --> 00:02:07,570 same on Linux and macOS but are different on 37 00:02:07,582 --> 00:02:11,000 Windows. And let's get started on Windows. 38 00:02:11,001 --> 00:02:14,948 So what you can do on Windows is simply press the 39 00:02:14,960 --> 00:02:19,000 Windows key or just go to the bottom of the screen 40 00:02:19,001 --> 00:02:25,000 and just type cmd or command prompt or terminal or whatever and you just click here. 41 00:02:25,001 --> 00:02:31,000 And this is going to open a terminal. I'm going to zoom in a little bit. 42 00:02:31,001 --> 00:02:36,678 Okay, and you can see that by default you are 43 00:02:36,690 --> 00:02:42,000 in your home directory, so /users/yourname 44 00:02:42,001 --> 00:02:44,989 or your username. To see what you get in there, 45 00:02:45,001 --> 00:02:48,000 you can use the dir command, so dir is going to 46 00:02:48,001 --> 00:02:51,769 give you all the files and folders that you 47 00:02:51,781 --> 00:02:56,000 have in your directory. Here you can see we have 48 00:02:56,001 --> 00:03:01,000 PyCharm project. If you want to go to that PyCharm project, you simply do cd, 49 00:03:01,001 --> 00:03:05,393 py and you can use tab for auto-completion, cd 50 00:03:05,405 --> 00:03:10,000 pycharm project. You can do dir another time and 51 00:03:10,001 --> 00:03:14,301 you can see you have my first project which is 52 00:03:14,313 --> 00:03:19,000 what we are using here. So cd my first project and 53 00:03:19,001 --> 00:03:23,115 then dir another time and you can see we have all 54 00:03:23,127 --> 00:03:27,000 the Python files that we have here on the IDE. 55 00:03:27,001 --> 00:03:29,989 So that's the same thing. And now let's say I want 56 00:03:30,001 --> 00:03:33,000 to run the add to ints.py. I'm going to do Python. 57 00:03:35,000 --> 00:03:38,418 So the Python command simply and then add to int. 58 00:03:38,430 --> 00:03:42,000 I can use tab another time and this is going to run 59 00:03:42,001 --> 00:03:45,601 the script and as you can see here, enter number 60 00:03:45,613 --> 00:03:49,000 one, enter number two and we have the result. 61 00:03:49,001 --> 00:03:52,113 And so this is going to execute the Python program 62 00:03:52,125 --> 00:03:55,000 the exact same way you are going to execute it 63 00:03:55,001 --> 00:03:59,075 when you press play on the PyCharm IDE. And now 64 00:03:59,087 --> 00:04:03,000 let's see how to do that on Linux and Mac OS. 65 00:04:04,000 --> 00:04:07,418 So the instructions here are going to be the same 66 00:04:07,430 --> 00:04:11,000 for Linux and Mac OS. So you have PyCharm with your 67 00:04:11,001 --> 00:04:14,597 programs and etc. You can open a terminal. So open 68 00:04:14,609 --> 00:04:18,000 a terminal also on Mac OS on your applications, 69 00:04:18,001 --> 00:04:21,020 utilities and terminal on Linux. Well Ubuntu for 70 00:04:21,032 --> 00:04:24,000 example, you can directly put the terminal here 71 00:04:24,001 --> 00:04:28,580 or search here for terminal. And then well you are 72 00:04:28,592 --> 00:04:33,000 going to need to find this file here. We want to 73 00:04:33,001 --> 00:04:36,811 launch add to ints. So you can see here the 74 00:04:36,823 --> 00:04:41,000 project is actually on that directory. So home, 75 00:04:41,001 --> 00:04:44,568 PyCharm project, my first project. And we are 76 00:04:44,580 --> 00:04:48,000 actually in the home folder. If you do PWD, 77 00:04:48,001 --> 00:04:55,000 you are in your home folder. So LS, you can see I have PyCharm project and then CD, 78 00:04:56,000 --> 00:05:00,584 PyCharm project. LS, I have my first project, my 79 00:05:00,596 --> 00:05:05,000 first project. LS to list the files. I have my 80 00:05:05,001 --> 00:05:09,305 add to ints.py. I can just do Python 3. So make 81 00:05:09,317 --> 00:05:14,000 sure you have Python 3. You can do Python 3 version 82 00:05:14,001 --> 00:05:16,400 to check that you have Python 3 correctly 83 00:05:16,412 --> 00:05:19,000 installed with a good version. And Python 3, 84 00:05:19,001 --> 00:05:23,032 add to ints.py, I press enter and it's working. 85 00:05:23,044 --> 00:05:27,000 So enter number 1, let's say 4, number 2 is 2, 86 00:05:27,001 --> 00:05:31,349 4 plus 2 is equal to 6. That's working. And for 87 00:05:31,361 --> 00:05:36,000 Mac OS, the commands are also LS and CD and Python 88 00:05:36,001 --> 00:05:39,609 3. Okay, that's going to be the same command. 89 00:05:39,621 --> 00:05:43,000 Congratulations, you can now create Python 90 00:05:43,001 --> 00:05:45,436 programs and run them from the terminal. In the 91 00:05:45,448 --> 00:05:48,000 rest of the course, I'm going to come back to the 92 00:05:48,001 --> 00:05:51,489 PyCharm IDE and run the programs from there. But 93 00:05:51,501 --> 00:05:55,000 on your side, you can decide instead to just run 94 00:05:55,001 --> 00:05:59,000 the programs from the terminal. That's going to be the same.