Python for AI #1: Dev Environment Setup

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to the python 4ai development course by assembly AI I'm Patrick and together with my colleague misra we will teach you how you can use Python to build with AI so first let's talk about the course outline and also talk about who this course is for so this course is a fast track to building machine learning models and AI powered apps and we expect that you already have some programming knowledge but you might be new to python or you already know some python but are new to Ai and in any case now you want to learn about AI so we don't explain programming Concepts here and we also don't explain python Concepts in detail instead you will pick up the python syntax on the go so we use a Hands-On approach and now let's talk about the course outline we splitted the course into five different lessons so five videos and the first one this one we talk about how you can set up your python development environment to build with AI then we talk about data cleaning and preparation with pandas then you will learn how you can build your first own machine learning model with a popular machine learning library then you will learn how to use model hubs to easily access state-of-the-art models if you don't want to build them on your own and as a alternative approach instead of using a model Hub we also talk about important apis for AI development so I show you a few important ones and also show you how to use them and of course if you want to skip some lessons and already know some Concepts feel free to skip them and watch only what you're interested in so let's start with lesson one and let's talk about the outline for this video here first we talk about how to install python so we start at the very beginning I will leave timestamps below so of course feel free to skip this as well if you know this then we talk about how you can install anaconda and how to use conda to manage different python environments and also install the packages you need then you will learn how to set up a local development environment with vs code for Python and lastly we talk about how to use two python notebooks and Google collabs if you want a cloud environment so let's get started so first let me show you how to install python on your machine so I'm on a Mac so I show it to you on a Mac but the approach is very similar on Windows and I also quickly mentioned how to do it on Linux so there are different ways how to do this and we do it the we had the official website so let's go to python.org and then you can click on down downloads and here it's already suggesting the latest version for my operating system in this case Mac OS and right now the latest version is Python 3 11.2 if you want another specific version you can scroll down here and here you find all the releases as well for example we can click on Python 3 10.10 and then again scroll down and here you find the different installers so if you're on window the recommended one is the windows installer 64-bit so then you can click on here and this will start the download if you're on Mac you can choose the Mac OS installer so this is what I'm doing here and then once the download is finished simply click on this and then follow the installation instructions and then it should be installed on your machine so this is how to do it for Windows and Mac if you're on Linux you can do it via the command line so first you could test if it's r installed sometimes it's already there so you can type Python 3 minus minus version and if you're seeing a version then it's already on your machine if not you can use those two commands so sudo apt get update and then sudo apt get install Python and you could also specify the version here and then this should install python on your machine and after installation we can now test this in the terminal so here we can type python minus minus version and now you should see the version you've installed on some systems like you've just seen on on the Linux you could also or you have to use Python 3 minus minus version in my case both will work and both will point to the same python version yeah just test whatever works on your machine so now we have python on our machine but before we write our first python code I want to install one more thing so this installation gave us the python standard library but often when we code with AI we use 3 third-party packages for example pandas I could learn tensorflow pytorch you might have heard of them these are all third party packages that we have to install on top and for this we are going to use there are also different ways how to do this in this video we use Anaconda which makes it super simple so let's learn about Anaconda now let's learn about anaconda and how we can use it to manage different python versions different python environments and also install third-party packages so for this you can go to anaconda.com products slash distribution and here you find some information about this for example with Anaconda we get access to the Anaconda repository and this features over 8 000 open source data science and machine learning packages and then we also get the conda command line interface and with this we can easily manage different python versions and we can easily install and update packages and their dependencies so for example we can type conda install pandas and then it will install pandas as a third-party package on our machine as well and you don't have to use Anaconda to do this and manage all of this but in my opinion it just makes your life a lot easier when you work with scientific packages so this video is a little bit opinionated so we're going to use Anaconda now and to install this you could either download it here this will give you the full um distribution platform but I prefer to install mini conda which is basically a stripped down version that gives us only what we need so for this you can type conda dot IO and now you will be redirected to this page and then you can click on Mini condom then here again you can check if mini conda is right for you and here again you will see that um Anaconda is the whole thing it will be three gigabyte large and if you don't mind installing each of the packages on your own we can do this also this simply gives us fast access to Python and the conduct commands and this is all that we need so we're going to install mini conda and here again you find different installers for Windows Mac and Linux so again choose your operating system and then download this in my case it's the m164 bit and then click on the installer and follow the instructions so if you run the installer you should have conda on your machine and you can test this by saying conda minus minus version and then you should see the version right here so let me give you a very quick crash course on how to use condom and we use condom mainly to manage different environments and then manage the packages within an environment and you can think of an environment as usually for each project you want to use a different environment and each environment gives you the same base python version so the standard library and then for each environment you want to install different packages so for different projects you might need different packages and you only want to install the packages you need so this way you keep your system and each environment clean and this is why we use environments and to create an environment we use the command conduct create and then minus n and then you give it a name I call this AI demo here here and now we could could hit enter you could also say python equal and then specify a specific python version you want so now let me use Python 311 now and now hit enter and this will create a new environment right now with python 311 so now this was created and now we can activate this with conda activate and then the name and also we can say conduct deactivate again so let's say conda activate AI demo and now in my terminal you see we now see the name of this environment and for example if we say python minus minus version now we see this is 311 because this is what conda installed so if we say conda deactivate again and then say python minus minus version then you see this is python 310 so this is what we installed on our system so let's activate this again and by the way you could see all the environments with conda and list and here you see I have already a few of them on my machine because I use this quite a lot for example one is called audio gym ML opencv and so on so let's activate the AI demo again and now let's learn how to install different packages here and to install different packages we use the command conda install and now for example let's install numpy a very popular package and you can add more in the same line so for example let's say also numpy and pandas and now hit enter and now it's installing numpy and pandas and also all their dependencies it found so let's hit enter and now this was installed as well of course later you can also remove this by saying conda remove numpy again or you can update the packages with conda update numpy or whatever you want and this is how you manage packages within an environment so like I said earlier you don't have to use Anaconda it just makes your life a lot easier but I also want to show you the default python way to install packages and this is instead of saying conda install and then the package name and by the way this might not always work because not all the packages are available via conda so instead of saying conda install you can say pip install and this is the default python package manager so you could also say pip install numpy I guess this would also work on your machine but we already installed this in this environment so let's try this with a different um third-party package so let's say pip install requests and now this will install this package within this environment and to uninstall this we say pip uninstall so the main difference between pip install and conda install is that pip focuses on python only and conda makes sure that also non-python related libraries are independencies are installed and this often makes it a lot easier to get the packages running and yeah this is the main difference between conda and pip but you should know both ways to install third-party packages now let's learn how to set up a local python development environment and for this I recommend either using vs code or pycharm these are the most popular Ides for python with pycharm you can get started right away and with Visual Studio code you have to do a little bit of configuration on the other hand it's more lightweight so in this video we we use Visual Studio code so you can go to code.visualstudio.com and then download the installer for your operating system again here I'm on a Mac so I downloaded the Mac installer and Then followed the instructions and now you should be able to type code Dot and this will open the editor in your current directory if you're doing this the first time it might not be available via the shortcut so of course you can also start at the normal way how you start applications so let's open it this way and then you can for example say open and then choose your directory and now this will open this directory so let's explore Visual Studio code first of all let me make this slightly larger for you so like I said you can configure this the way you want so I will change the font size and the zoom factor a little bit and now let's take a look how this code works so on the left we see the Explorer and here we see the folder right now we don't have any files in it so we can click on new file and create our first python file main.pi all python files end with Dot py and now here we could start writing code but before we do this the very first time we also have to install one extension so let's click on extension and here you can install different extensions to configure your IDE so here let's search for Python and install the official python extension from Microsoft this will give you things like intellisense linting debugging even 2.0 notebook support which I show you in a few moments so go ahead and install this here and now this is the only one you need I also like to have the code Runner extension so with this you can run python files and other languages more easily so I installed this here as well and now we can go back here and start writing our first line of code so the typical print hello world and now we can click command s to save this and now there are different ways to run a python file if you do it from the terminal um you can go into this directory and here we have the main.pi file and now to run this we have to say Python main.pi and also notice that here I activated this environment before so now let's say Python main.pi and enter and then we see the output hello world so this is how to run it from the terminal you can also of course run it directly from Visual Studio code by clicking on this Arrow here so if you run this then there are different options you can click on run code I think this is because of the code Runner and then you simply see the output here or you can click on run python file and now it will go to the terminal window and you notice that it already activated it it activates the environment so it is smart enough to know that I want to use this in here and then it runs the file and it gives us a terminal window in here so here we could also say conda deactivate for example or conda activate the environment again you also might notice that in the bottom we can select the python environment we want so if we open this then here are the different ones I have on my machine so I showed you this before I have a lot of conda environments so here you can switch to different ones and yeah make sure to always use the one you created for your project so here I select AI demo and here for example we install numpy so now if we want to use this we can type import numpy and the convention is to import this SNP then we don't have to type everything and now for example we can create a numpy array by saying a equals NP dot array and then we give this a list so here we use brackets and then let's say one two and three those two values and then let's also simply print this and now here um if we run this so we say python main.pi then this should work here it prints this and this is because we are using this environment for example if I say conda deactivate and now if I say python main dot Pi then we get an error module module not found error no module name numpy and this is because we are not using this environment so we want to activate this again and also within Visual Studio code for example if I select a different python interpreter for example this one or no this one is actually working let's try this one here numpy is not installed and here this is underlined because it's not detecting this so our IDE knows that numpy is not available in here so make sure to also select the environment Here and Now everything should work and this is how you can code and python on your machine with Visual Studio code so now you know how to work with vs code and write python files and now I want to show you one more thing and this is how to work with notebooks or so-called two-parter notebooks a two-parter notebook is a web-based interactive platform to write python code and the experience with it is quite different than with a normal python file and you will know what I mean in a few moments but notebooks are super popular among machine learning engineers and data scientists because it's super convenient to experiment with your code and this is perfect for data visualization for example and also for model development so let me show you how to work with notebooks and there are three ways how you can use them in my opinion the first option is to use this directly inside of vs code here the second option is to use the classic two python notebook platform and the third option is to use a Google collab a cloud-based option from Google so I will show you all three options so first let's start inside vs code and this is supported if you install the python extension which is pretty cool the only thing we have to do is create a new file with the ending I pi and B so let's create a file let's call this my notebook and then we have to say dot I Pi N B I think this stands for iron python notebook and now hit enter and now this created The Notebook then here make sure to also select your python environment so here the AI demo and now here we can write the normal python code so the syntax is the very same and then here we can click on run and if you do this the first time I think it yeah it will prompt you to install the IPI kernel so we can click on install and now this will install the kernel so now this was installed and also the code here was executed and now we can click here on Plus Code and insert a new code cell or also a markdown cell so let's go ahead and select a new code cell and now here we can write some more code so say print hello um second cell for example and then let's run this code as well so this will run cell by cell and now the results are saved so um for example if we create some variables in here let's say a equals five and then we can run this and then later if we go to a different cell so let's create a third cell and then we want to print a so this was the variable then now it still knows this and this is super cool because for example now we can go back and change our code for example now we want to say a is 7 then of course we have to rerun this cell again and now if we also run this cell then you see a is now 7. so we can go fourth and back and change the code and experiment with all the different cells and also the results are saved so here you see um the different checkpoints and yeah this just makes it super cool to experiment with your code and this is how you can work inside a inside vs code directly and now let me show you how to use the two python notebook platform so to use the platform you use your terminal and also make sure that you have installed this and there are quite different ways how you can install this often with Anaconda you can already use this so you can say chew pyter notebook and then it should start the server but if this does not work and also if it doesn't show your environment inside the notebook then I will show you these commands from stack Overflow how you can install this so option one is to run to the two python server and the kernel inside the conda environment so for this you again create your environment and actuate this and then you say conda install Two fighter and then you should be able to use two python notebook or the second option is to create a special kernel for the conda environment so for this again activate your environment and then say conda install IPI kernel and then ipiker IPython kernel install minus minus user minus minus name and then the name of your environment and then this is important make sure to deactivate your environment and then say conda install two Python and then two python notebook so let me try two python notebook inside the environment and now let's see what happens so this will now start the server on our Local Host this is the classic two python notebook server and here for example you see we already have one and you can also now click on new and now here you should be able to select the environment and I'm not seeing the AI demo environment here so I have to do some installation first so let's me close this again and here let me say um control C and quit the server again so let's try the um second approach from here so let's try inside of the environment let's try conda install ipy kernel and hit enter so this is already here so let's try the second one so now we want to say I Pi python kernel install minus minus user minus minus name and here we call this a i demo this will now install the kernel for this environment and now we say deactivate and here we say two pyter notebook and now it should start the server again and if we click on new we see it says AI demo so now let's select this and now here again we have the cells so here we can say print hello and let's for example run this so you can say shift and enter and now it will run this cell and insert a new one and here we should be able to import numpy s and P then again we say shift enter and this works because it correctly uses this environment and then we can use numpy so we can say a equals numpy dot array and then again let's create a list and then again here we can say print a and then shift enter and now it's running this cell and then here again we can change the cells as we want and the results are saved so this is the second way and the Third Way which is the easiest by far is to Simply use a Google collab and this is a cloud-based environment so for this you can go to collab.research.google.com and hit enter and then you can create a new notebook here and now this will start a cloud-based notebook for you and here again you have different cells so here again we can run code and what is super cool about a notebook is that first we get a GPU for free so we can click on runtime and then change the runtime type to a GPU so if you work with deep learning libraries like pytorch and tensorflow then a GPU is super useful and the second cool thing about a notebook is that here we get a pre-configured environment so in the background somewhere on a server there's a Linux machine running and on the machine we already have a python environment and inside the environment we already have all the or most of the packages we need for example here we already have numpy I we also already have Pi torch so we can say import torch we can also import tensorflow as TF for example and if we run this then this should work so yeah this executed successfully so now we can again select a new cell and then continue coding so yeah this is a cloud-based version of a notebook that Google provides for free and like I said this is the easiest option to get started with this so it's super cool that it has a GPU and it supports many deep learning packages out of the box but yeah these are the three options so in the next one we actually start writing more python code and for this we also use a two python notebook so let's go to the second lesson with misra
Info
Channel: AssemblyAI
Views: 14,179
Rating: undefined out of 5
Keywords:
Id: yTJxDzqo4fQ
Channel Id: undefined
Length: 27min 39sec (1659 seconds)
Published: Wed Mar 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.