1 00:00:00,000 --> 00:00:02,100 [no audio] 2 00:00:02,100 --> 00:00:04,099 Friends here we are going to see 3 00:00:04,099 --> 00:00:07,800 how to run Python Script on your Windows 4 00:00:07,800 --> 00:00:10,900 operating system or on Linux operating system, 5 00:00:12,500 --> 00:00:15,300 right, or any other Unix-like systems. First 6 00:00:15,300 --> 00:00:17,200 let me go with Windows operating system. 7 00:00:17,500 --> 00:00:21,000 So already we know from our previous videos how to run Python 8 00:00:21,000 --> 00:00:24,200 Script on your Windows operating system, and that too from 9 00:00:24,200 --> 00:00:25,100 command line guys. 10 00:00:25,100 --> 00:00:30,300 So if you want to run your Python Script from GUI editors, in 11 00:00:30,300 --> 00:00:34,400 GUI editor itself you have an option to run your Python 12 00:00:34,400 --> 00:00:39,000 Script. But first of all, we are going with command line. 13 00:00:39,300 --> 00:00:42,000 Then later after some time 14 00:00:42,000 --> 00:00:46,800 we will see how to use Python Script in GUI editors, or how 15 00:00:46,800 --> 00:00:51,100 to run your Python Script using your GUI editors. For time 16 00:00:51,100 --> 00:00:53,100 being we are going to work with from command line. 17 00:00:53,100 --> 00:00:55,200 Let me open my Windows command line first. 18 00:00:55,200 --> 00:00:57,400 [no audio] 19 00:00:57,400 --> 00:00:59,000 So from our previous videos already 20 00:00:59,000 --> 00:01:01,800 we have some Python Script under this location. 21 00:01:01,800 --> 00:01:05,400 Let me enter into that and see some Python Scripts are there. 22 00:01:05,700 --> 00:01:08,400 Let me take simply 'usage_of_comments' 23 00:01:08,400 --> 00:01:11,500 Let me take a simple example, 24 00:01:11,500 --> 00:01:14,800 [no audio] 25 00:01:14,800 --> 00:01:19,700 or type simply 'hello', this is one Python Script, right? 26 00:01:20,500 --> 00:01:24,300 So if you want to run Python Script from Windows, first thing 27 00:01:24,300 --> 00:01:27,600 you have to check it whether 'python --version', 28 00:01:28,000 --> 00:01:30,600 if it is working. Then directly 29 00:01:30,600 --> 00:01:33,900 you can run 'python', then your script name. 30 00:01:33,900 --> 00:01:36,000 [no audio] 31 00:01:36,000 --> 00:01:39,000 Sometimes if you run 'python', right, let's say something like 32 00:01:39,000 --> 00:01:44,000 this, and if you run, so you will get "python is not recognized 33 00:01:44,000 --> 00:01:45,600 as an internal or external command". 34 00:01:45,700 --> 00:01:47,300 Of course, I have given some wrong name. 35 00:01:47,800 --> 00:01:51,100 But sometimes if you run in this way, 'python --version', 36 00:01:51,100 --> 00:01:53,400 this command, you will get this output. 37 00:01:54,200 --> 00:01:56,900 So at that time how you can run means, nothing 38 00:01:56,900 --> 00:02:00,400 is there, just simply provide complete path of your 'python', 39 00:02:00,400 --> 00:02:02,600 where you install your 'python.exe'. 40 00:02:02,600 --> 00:02:05,400 [no audio] 41 00:02:05,400 --> 00:02:06,600 You will get your output. 42 00:02:07,500 --> 00:02:10,300 Or simply copy this path, 43 00:02:11,800 --> 00:02:14,300 if you want to work like this, if you want to work like this, 44 00:02:14,600 --> 00:02:18,300 what you have to do is, just to go to your 'c', 45 00:02:19,500 --> 00:02:20,900 right, then there 46 00:02:20,900 --> 00:02:22,800 [no audio] 47 00:02:22,800 --> 00:02:25,000 just 'C: Local Disk', 48 00:02:25,000 --> 00:02:29,000 so where you installed your Python, Python 3.7. So here you have 49 00:02:29,000 --> 00:02:32,400 Python, right? Copy this path. Copy this path, 50 00:02:33,600 --> 00:02:40,100 and click on 'This PC->Properties'. So this is on your Windows guys. 51 00:02:43,300 --> 00:02:44,700 'Advanced system settings-> 52 00:02:44,700 --> 00:02:49,300 [no audio] 53 00:02:49,300 --> 00:02:50,400 Environment Variables-> 54 00:02:52,200 --> 00:02:54,000 PATH'. You can edit this 'PATH'. 55 00:02:54,700 --> 00:02:57,100 So already I added that, right? 56 00:02:57,100 --> 00:02:58,700 That's why no need to add any extra path. 57 00:02:58,700 --> 00:03:02,900 If you want to add once again, you can add it. Say simply 'New' 58 00:03:04,400 --> 00:03:08,100 in this way. But already we have that Python 3.7. Just simply 59 00:03:08,100 --> 00:03:12,500 I'm canceling. So once if you add your path here, then 60 00:03:12,700 --> 00:03:16,500 by reopening your terminal your Python will work in this 61 00:03:16,500 --> 00:03:18,500 way 'python --version'. 62 00:03:19,600 --> 00:03:22,200 So if you get in this way, now we are ready to run your 63 00:03:22,200 --> 00:03:24,800 Python Script from your Windows operating system, from command 64 00:03:24,800 --> 00:03:27,100 line of your Windows operating system in this way. 65 00:03:27,100 --> 00:03:29,900 Simply 'python ', your Python Script. 66 00:03:31,200 --> 00:03:33,900 So that is very simple to run your Python script on your 67 00:03:33,900 --> 00:03:35,000 Windows operating system. 68 00:03:35,700 --> 00:03:38,400 Let me take same Python Script where we have that, 69 00:03:39,500 --> 00:03:42,800 and I'm going to copy this to your Unix-like systems. 70 00:03:43,200 --> 00:03:44,800 Now this is my Unix-like system. 71 00:03:44,800 --> 00:03:49,900 Let's say, see that. What is my operating system? 'uname', right? 72 00:03:52,300 --> 00:03:54,800 Now what I am doing is, let me create here 73 00:03:54,800 --> 00:03:57,700 also some Python Scripts. 74 00:03:57,800 --> 00:04:01,800 So this is my in Linux box terminal, guys. 75 00:04:02,500 --> 00:04:03,900 Sorry, what happened? 76 00:04:03,900 --> 00:04:36,400 [no audio] 77 00:04:36,400 --> 00:04:39,800 'bash mkdir'. 78 00:04:41,300 --> 00:04:43,400 I'm not sure why it has happened. 79 00:04:43,400 --> 00:04:45,800 No problem. Just now we created called 'PythonScripts'. 80 00:04:45,800 --> 00:04:47,000 Let me enter into that. 81 00:04:47,000 --> 00:04:49,200 [no audio] 82 00:04:49,200 --> 00:04:50,100 So we don't have anything. 83 00:04:50,100 --> 00:04:53,300 Let me create simply, so guys just observe that whether 'vi' 84 00:04:53,300 --> 00:04:54,300 is there or not. 85 00:04:55,200 --> 00:04:57,900 Yes, it is there. 'vim' is there or not? 86 00:04:59,100 --> 00:05:02,100 Both are there. You can use either 'vi' or 'vim' editors on your 87 00:05:02,100 --> 00:05:03,100 Unix-like systems. Now, 88 00:05:03,100 --> 00:05:07,900 I am using 'vim' because if you use 'vim' no, it will give some colors. 89 00:05:08,900 --> 00:05:14,200 Simply I'm writing 'hello_world.py', and something I am 90 00:05:14,200 --> 00:05:15,400 pasting your lines. 91 00:05:16,200 --> 00:05:18,800 So already we have this code from your Windows operating system. 92 00:05:19,700 --> 00:05:22,400 Now guys, after writing your Python Script just check it 93 00:05:22,400 --> 00:05:23,900 whether you have Python or not. 94 00:05:25,500 --> 00:05:28,700 So simply 'python', by default you will get any one of the 95 00:05:28,700 --> 00:05:30,300 Python versions on Unix-like systems. 96 00:05:30,300 --> 00:05:33,200 That's why if you run 'python', you're getting some 2.7., 97 00:05:33,300 --> 00:05:34,500 whatever it maybe, any version. 98 00:05:34,500 --> 00:05:36,600 [no audio] 99 00:05:36,600 --> 00:05:39,400 So already we know how to install Python 3 on your Unix-like 100 00:05:39,400 --> 00:05:42,200 systems. I already installed and we have one video for that, 101 00:05:42,200 --> 00:05:46,000 right. Just go through that 'How to install your Python 3'. Right. 102 00:05:46,500 --> 00:05:49,800 Now I want to run my Python Script using Python 3. 103 00:05:50,100 --> 00:05:53,500 Simply 'python3 ', your script name. 104 00:05:54,100 --> 00:05:57,500 This is one way. If you want to run your Python Script using 105 00:05:57,500 --> 00:06:01,600 Python 2, simply 'python ', script name. Guys 106 00:06:01,600 --> 00:06:03,200 this is on your Unix-like systems. 107 00:06:03,200 --> 00:06:04,300 Don't get confused. 108 00:06:04,300 --> 00:06:06,600 [no audio] 109 00:06:06,600 --> 00:06:10,200 Guys, this is one way, I mean the same way how you are running your 110 00:06:10,300 --> 00:06:12,200 Python Script on your Windows operating system. 111 00:06:12,400 --> 00:06:16,900 So now, as of now whatever we discussed, I mean to run your 112 00:06:16,900 --> 00:06:20,400 Python Script this is the common procedure on your Windows 113 00:06:20,400 --> 00:06:24,400 as well as Unix-like systems. But in your Unix-like systems, 114 00:06:24,400 --> 00:06:30,000 you have one extra procedure also to run your Python Scripts. 115 00:06:30,200 --> 00:06:33,700 What is that means? So before running your, before writing 116 00:06:33,700 --> 00:06:35,300 your Python Script, just check it 117 00:06:35,300 --> 00:06:39,100 which Python 3 you are having. This is the location, right? 118 00:06:39,800 --> 00:06:45,300 Copy that. Open your script. Very first line just mention 119 00:06:45,300 --> 00:06:47,200 [no audio] 120 00:06:47,200 --> 00:06:51,300 in this way '#!', then your path where your 121 00:06:51,300 --> 00:06:57,500 Python is there, after that just provide execution 122 00:06:57,500 --> 00:06:59,000 permission for your file. 123 00:06:59,600 --> 00:07:02,900 Now you can run your script in this way, './hello_world.py'. 124 00:07:02,900 --> 00:07:06,100 No need to provide 'python ', because already inside 125 00:07:06,100 --> 00:07:09,600 of our script very first line we mentioned about Python, which 126 00:07:09,600 --> 00:07:13,500 Python you want to use to run your script. You're getting 127 00:07:13,500 --> 00:07:15,200 output, no? Observe your script. 128 00:07:16,600 --> 00:07:20,000 Right. So we mentioned, so here you can mention whatever the Python 129 00:07:20,000 --> 00:07:21,700 you need to run your lines. 130 00:07:22,500 --> 00:07:24,800 So I want Python 3 to run my code, 131 00:07:24,800 --> 00:07:28,600 that's why very first line with this symbol, '#!' 132 00:07:28,700 --> 00:07:32,600 I am mentioning my Python path, and this line is called 'Shebang 133 00:07:32,600 --> 00:07:38,800 Line'. The purpose of this line is, you are mentioning an interpreter, 134 00:07:38,800 --> 00:07:41,400 which interpreter you are going to use to run your Python 135 00:07:41,400 --> 00:07:42,700 Script. That's it. 136 00:07:42,700 --> 00:07:45,900 [no audio] 137 00:07:45,900 --> 00:07:51,000 Right. So if you want to use some any extra, other Python which, 138 00:07:51,000 --> 00:07:55,300 actually we mentioned some default Python version, Python 139 00:07:55,500 --> 00:07:58,000 version inside of your script, right, like Python 3. 140 00:07:58,600 --> 00:08:00,000 I don't want to use Python 3. 141 00:08:00,000 --> 00:08:02,400 I want to use Python 2. Then simply externally 142 00:08:02,400 --> 00:08:05,500 you can mention 'python', and then your "hello", 143 00:08:06,700 --> 00:08:07,700 it will also work. 144 00:08:08,500 --> 00:08:10,900 If you mention inside of your script we'll take that one. 145 00:08:11,700 --> 00:08:15,500 If you don't mention, you can run from outside. Even though 146 00:08:15,500 --> 00:08:17,900 if you have, if you mention from outside we'll take this Python. 147 00:08:20,000 --> 00:08:24,800 That's it. Okay. So guys on your Unix-like systems, 148 00:08:24,800 --> 00:08:27,100 anyway you know the common procedure for your Windows as 149 00:08:27,100 --> 00:08:31,400 well as Linux, simply 'python', required 'python', then script name. 150 00:08:31,400 --> 00:08:33,600 [no audio] 151 00:08:33,600 --> 00:08:35,400 But on Unix-like systems, 152 00:08:35,400 --> 00:08:38,700 [no audio] 153 00:08:38,700 --> 00:08:43,900 this is the best way. That is first find which Python you 154 00:08:43,900 --> 00:08:48,200 want. If you want to go with Python 2, just type which Python, 155 00:08:48,400 --> 00:08:49,400 or Python 3. 156 00:08:50,200 --> 00:08:52,500 So whatever the path you are getting, right? 157 00:08:52,500 --> 00:08:57,100 Let's say some script 'hello.py'. So very first line mention 158 00:08:57,100 --> 00:09:01,800 your which Python 3 output, that is location of your Python, 159 00:09:01,800 --> 00:09:03,700 [no audio] 160 00:09:03,700 --> 00:09:06,200 and this line is called 'Shebang Line'. 161 00:09:06,200 --> 00:09:09,900 [no audio] 162 00:09:09,900 --> 00:09:10,900 Okay. 163 00:09:10,900 --> 00:09:13,800 [no audio] 164 00:09:13,800 --> 00:09:15,600 Just comment that line, 'shebang line'. 165 00:09:16,200 --> 00:09:20,700 So the purpose of Shebang Line is which type of interpreter 166 00:09:20,700 --> 00:09:24,600 you're using to run the lines which are there in your code. 167 00:09:24,600 --> 00:09:26,800 Let's say simply 'print("hello")' 168 00:09:26,900 --> 00:09:29,600 This is also one simple Python Script, just to display, "hello". 169 00:09:30,300 --> 00:09:33,300 So after this what you have to do is, just provide execution 170 00:09:33,300 --> 00:09:34,900 permission for your file, 171 00:09:34,900 --> 00:09:36,700 [no audio] 172 00:09:36,700 --> 00:09:38,300 whatever the script you have. Then run 173 00:09:39,100 --> 00:09:41,100 'hello.py'. Okay. 174 00:09:41,300 --> 00:09:45,000 So guys here I am providing './' because I am running 175 00:09:45,000 --> 00:09:47,900 from the current location where my Python Script is there. 176 00:09:49,500 --> 00:09:52,500 So here my Python Script is there, that's why I am running './hello'. 177 00:09:53,700 --> 00:09:57,900 Suppose you are in the home location, you are in a different 178 00:09:57,900 --> 00:10:00,200 location, and your Python Script is there in a different 179 00:10:00,200 --> 00:10:03,500 location. At that time if you want to run your Python Script 180 00:10:03,500 --> 00:10:06,000 from any one of your path what you have to do is, you have 181 00:10:06,000 --> 00:10:07,700 to provide complete path. 182 00:10:08,700 --> 00:10:09,700 That's it. 183 00:10:11,200 --> 00:10:14,300 So if you are in the location of where your Python is there, 184 00:10:14,500 --> 00:10:15,900 here we don't have Python, right? 185 00:10:15,900 --> 00:10:17,700 [no audio] 186 00:10:17,700 --> 00:10:20,600 If you don't have Python Script in this location, then you 187 00:10:20,600 --> 00:10:23,500 have to run always your Python Script by providing your complete path, 188 00:10:26,100 --> 00:10:31,100 or just enter into your required location where you have your 189 00:10:31,100 --> 00:10:32,500 Python, from there 190 00:10:32,500 --> 00:10:34,000 you can run simply './'. 191 00:10:35,500 --> 00:10:36,800 Right. So guys 192 00:10:36,800 --> 00:10:39,700 this is the way how you can run your Python Scripts on your 193 00:10:39,700 --> 00:10:42,600 Windows and Unix-like systems, okay. 194 00:10:43,100 --> 00:10:45,100 Okay guys, thank you for watching this video. 195 00:10:45,100 --> 00:10:52,600 [no audio]