How to Install Python on Mac OS and How to Run Python code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Applause] hey guys python is a very powerful programming language it's also one of the most famous programming languages today especially in the field of data science and machine learning in this video i'm going to show you how to install python on mac and i'm also going to show you how you can start writing and executing your first python program i'll show you how to write and execute a python program in three different ways one by using idle which is an ide which comes along with your python installation number two by using any text editor that you may have to write your python program and then executing that program using the terminal and finally by using visual studio code or simply vs code which is considered to be one of the best ides for python so let's begin so before we can get started with python installation it's important to check if python is already installed or if which version of python is already available in the machine to do that go to your terminal and then type python-version this will actually show the version python 2. this is actually pre-installed with your mac os what we are trying to do here is install python 3 so to check if python 3 is already installed just type python 3 space dash dash version and now you can see that i am getting an error message so this means python 3 is not present in this system so let's go ahead and install python3 to do that just go to your browser and type python the first website that you see should be python.org which is official python website click on download and it should auto detect that you're on mac os and it will suggest the latest uh python version for mac os in this case it is the python 3.9.1 and let's download this file so once the once the download is completed let's go ahead and install it the installation of python is pretty straightforward it's almost similar to any other software that you might have already installed in your machine so let's just proceed and let's enter the password the installation should complete in a few seconds we'll close this and as you can see congratulations python 3.9.1 for mac os was successfully installed so let's close this we can move this to bin and we can close the browser so python is installed to verify again go back to your terminal and then again type the same command python 3 space dash dash version and now you can see that it's displaying python 3.9.1 this is the version of python that is currently installed in our machine so python is installed now let's get started writing our first python program to do that i'm going to show you three different ways the first one is by using idle idle is an ide which is which actually comes along with your python installation so you can just go to your launchpad and you can see it here idle so click on that and it shows you this interpreter this is a python idle interpreter basically you can write python commands here and see the output straight away so let's just test it out so let's write hello world and as you can see when i execute it's displaying the output or let's say if i want to assign a value to a variable a equal to phi and if i want to check the value of that variable i can check it like this so this is an interpreter where you can write any python commands to check it but if you want to write a program then you would like to open a new file so either go to file and click on new file or just press the shortcut control yen so this will open a file editor so let's write a small sample program here let me just print like what is your name and then save the name in the variable name and then print the name okay so i've written a simple program let's save it i'm going to name it like uh program 1 dot py it's important to have the file extension as dot py this will tell to the interpreter that this is a python file and it will execute it like a python file i'm not going to change the path uh this is the default path where idle is installed so let me go ahead and save this now to execute this file or this program what we need to do is we can go to run and then click on run a module or as a shortcut you can just press f5 so when i click f5 it's executing this program and you can see here it's asking for my name so let me enter my name and i can see the output so the important thing to note here is you need to be in your program window to execute the command that is click run run module or f5 and then the output will be displayed in your interpreter window so that's an important thing that you should note when you're using idle now let's close this let's try to write the similar program using another way that is by using any text editor you can use any text editor that you have already installed in your machine so i have already installed atom and let me just open atom so and let me open a new file and let me again uh type the same program so i've written the program and let me save it this time i'm going to save it inside another folder which is inside my documents folder which is the practice python and let me name this program as let's say program 2 dot py and let me click save now so i have written my python program in a text editor in this case atom now to execute this what you can do is just go to your terminal and here the first thing that you need to do is you need to go to the path where the file is placed in my case my my file is placed inside inside my document so let me go to my file let me go to documents practice python and this is a program that have written you can just press ctrl i and it will show here you can see the full path where this file is placed copy that and go back to your terminal so and then here you just type cd and paste the path so now my terminal is pointing it is actually pointing to that particular path where my python program is placed to execute this python program then just type python 3 space the program name in this case the program name is i think program 2 dot py so i execute and the python is executing let me enter a name and you can see the python program has been executed successfully so this is how you can use a text editor to write your program and save it and then use the terminal to execute that particular program so this is the second way and now let me show you the third way for the third wave what i'm going to do is i'm going to use vs code so i have already installed vs code so vs code is one of the best ideas for python along with pycharm and nope jupiter notebook there may be a few others as well so but definitely vs code is one of the best so the first thing that you need to do to use vs code for python is you need to install and python extension so to do that just come here the last section here which is the extension section just type python it should show the most popular or the most downloaded python extension in this case this particular extension has been downloaded more than 29 million times so let me just install that why this is required is because this will help the vs code to execute your python programs it also has many additional features like it can do your code formatting it has intellisense etc so it's pretty useful to have this so now the python extension has been installed let me open a folder and i've already opened this folder here practice python so inside this folder let me go ahead and create a new file i'll just press ctrl n and then again type the same program so i've written this program let me save it i'll give a name like program three dot p by and i'll place it in the same path practice python let me save it so now my python program has been created and saved to execute this you can just click on this button here which is the run button so when i click on that your program will execute and you can see here your python your program is executing it's asking for a name and let me just enter my name topic and so the program is executed so this is a third way how you can use vs code to write your program and then execute it using the same editor so i hope this was helpful and hopefully you can follow any one of this method to start practicing python if you like this video please make sure to like and subscribe i'll be posting more videos on python sql database and many more so thank you [Music] you
Info
Channel: techTFQ
Views: 615,079
Rating: undefined out of 5
Keywords: install python on mac, install python, how to install python, how to install python on mac, how to run python code, run python code, run python code on mac, python, python 3, python3, python mac, python mac install, how to run python code on mac, execute python code, execute python code on mac, how to execute python code, how to execute python code on mac, run python code using IDLE, run python code using VS Code, run python code using terminal, IDLE, VS Code, python tutorial
Id: M323OL6K5vs
Channel Id: undefined
Length: 9min 53sec (593 seconds)
Published: Mon Jan 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.