Welcome to this bonus video, I decided to create this lecture as a result of many questions from people complaining that they can't run a Python script, as I showed in the previous videos, also receiving the no such file or directory error in the windows command line, or a similar error in other operating systems. So I'm going to show you the most frequent causes of such errors when you are running your Python script as I have identified them while troubleshooting these issues raised by other students. So first of all, let's open up the windows command line. And let's pause here for a moment. I noticed that some people are trying to run a Python script from within the Python interpreter which is incorrect. So this is the Python interpreter after inserting the Python command and hitting Enter, but this is not the place from where you should be running your pythons.
Crypts, instead, let me exit, you should run your Python scripts from within the windows command line. So from this default prompt right here, now that we have the first common mistake out of the way, let's focus on the Python command itself and the path to the Python script on your operating system. First of all, to make sure that you get the correct and complete path to your Python script, you can just go to the folder where your file is stored. So let me do this. In my case, it is in my files, folder underscore one. And this is the file right here file one dot p y.
Now you have to click up here in this navigation bar. Notice that as soon as you click this bar once windows shows you the full path to the current folder, just copy this path and paste it after the Python command inside the windows command line. So let me write in Python space. And now let me paste in this file path. Okay, now All you have to do is add another backslash and insert the name of your file, including the dot p y extension. So let me say that again, because most people often forget it include the dot p y extension, not just the name of the file.
So in my case, that would be file one dot p y. Another thing to keep in mind here is that file names can sometimes be case sensitive on some operating systems, such as Ubuntu, for instance. In that case, if you named your script file one dot p y, with all lowercase characters, you should also use the same case convention when running the file from the command line. So remember that in some circumstances, file, one dot p y may not be the same as file one dot p y written with a capital F. Okay, now back to our Python command. Let me hit enter to run the script. Notice that I still get an error.
Although I followed all the rules discussed above. So I'm running the script from the windows command line not from the Python interpreter, I have copied and paste the correct path right from the windows navigation bar. I have added the.py extension to the filename, and there are no issues regarding case sensitive names, and I still got an error. Why is that? Well, because of something that many people usually overlook, and that is the space inside the file path. Notice that the first folder over here is called my space files with a whitespace between the words my and files.
To fix this issue as well. All you have to do is enclose the entire path to the file in between double quotes and this way any spaces in your path will be ignored. So let me add the double quotes at the end and at the beginning of the file path. Now let me hit enter once again, and the script is executed successfully. Great job. Last but not least, if by any chance, you have both Python two and Python three installed on the same operating system, and the Python command throws any kind of errors, after the checks we've done so far in this video, make sure to try using Python three instead of Python when running the command.
So that would be something like this, for example, Python three, and then the path to the file. This way, you can make sure that your Python script is executed using the most recent major version of Python, which is Python three. However, since Python two is slowly getting deprecated, I see no real reason to keep it installed on your system, unless you have a specific use case for it. On the other hand, if you're a beginner in Python, you most probably have only Python three installed and that's the version that you should focus your learning efforts on Okay, having that said I hope this video has been useful and I will see you in the next one.