Anaconda (Conda) for Python - What & Why?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to this video if you did your first steps in python you probably used packages because python is a language you can well basically use for anything so we need these packages to tailor python according to our needs now the problem might be that you don't have one single project in python you might have multiple projects for multiple purposes and you have all these packages installed globally on your machine now this can cause some problems or at least inconveniences for that we can use so-called virtual environments in python what these are why we use them how we use them and how we can specifically use them in connection with conda well this is what we will have a look at in this video so let's get started with the big picture first i mentioned it in the beginning python is a really versatile language you can use it for basically anything some application examples would be web development data analysis or artificial intelligence machine learning call it however you want the thing is that each of these purposes requires specific packages for example for web development we might use flask for data analysis we might use matplotlib we talked about that on this channel already and for artificial intelligence we can use something like pytorch now these packages are not related at all because they have different purposes why would i need flask if i just want to create a big chart in jupyter notebook for example additionally you also might use different versions of python itself for example you might use python 3.5 for your webdiv project and python 3.7 for a data analysis project just to name an example so you have these different version topics and this different package topic in general the issue is you only have one computer in the end so the best thing would be if you would buy free computers right you could buy a web development computer for your python purposes you could buy a data computer for your data analysis purposes and you could buy an ai machine just for your python installation with all the required ai packages now that's of course not the solution here the solution is that we basically have an unlimited amount of computers on our single computer by using so-called virtual environments and these environments let us do exactly what you can see right here we can create separate environments for each purpose of python so we can create an environment for our webtive project and one for our data analysis project and just to be clear we are not limited to one environment for one specific purpose actually we can have multiple web dev environments we can have multiple data analysis and whatsoever environments so we can use basically an environment a specific environment for each single project that we have in python so that's the big picture that's why virtual environments are really helpful when it comes to different python applications and different packages with different versions so how can we install these environments how can we use them well it basically starts with the installation of python already for that i will have a look at three different well steps you could say the installation itself the purpose of a specific tool or thing we install and the usage of this tool set you could say now one way could be to simply install python from python.org with that you would also install pip python's integrated package manager and well the purpose of this package manager is to manage your packages quite simple actually now i talked about the virtual environment though and with that default setup you only have one global environment you could say your machine now if you want to manage different environments on your computer then you could install virtualenv this is a tool you can download and install and it serves exactly that purpose it allows you to manage virtual environments in python this is one way how you could do this nothing wrong about that there is an alternative though actually there are more alternatives but i just want to have a look at this alternative here the alternative would be to use anaconda or miniconda both are python distributions also something we talked about on this channel already and anaconda or miniconda have the great advantage that they install conda on your system now what is conda well conda is basically both it's a package manager and it allows you to also manage your virtual environments so to create and manage these virtual environments on your machine now what's the usage of these two when would i choose which approach as i said these are just two examples though well the normal python pip virtual amp approach is basically made for any purpose you can do this you can create environments user packages nothing wrong about that so why would i use anaconda or mini conda then well anaconda or miniconda come with a lot of packages required for data analysis and data science or at least these packages make working in these fields a lot easier and they also make it easier for beginners to get started with python that's why we will follow this anaconda miniconda approach here and we want to have a look at how we can do the package management and the virtual environment management with conda so that's our setup right here now let's install anaconda or as i said mini conda first for that you can either go to anaconda.com right here and then scroll down a bit and then download the anaconda distribution that's the and choose your system and then download it right here that's one approach nothing wrong about that with that you will also install the anaconda navigator which includes a graphical user interface which makes the well installation and working with python a bit easier but it also installs a lot of packages by default so it's kind of big you could say and i want to have a look at these package installation and environment management in a bit more detail so i want to start from scratch that's why i don't want to use anaconda right here but i want to stick to miniconda miniconda as you can see right here is a free minimal installer for conda so what it basically will do is it will just install conda and then python itself and then just some basic packages and it will still allow us to install any additional packages with chip with anaconda if we want them so we have the option to do so but we don't install all the packages by default on our machine therefore miniconda is a lot smaller it's a bit more difficult to get started maybe because you don't have this graphical user interface you'll have to navigate through the terminal or the command prompt but we will have a look at that not too difficult and yeah that's the reason why i want to use miniconda here the installation on the mac is quite easy by the way you can find links to these pages of course in the video description below the video and yeah for the mac we can now simply decide if you want to install mini conda or anaconda as i said i want to use mini conda so we click right here and now you can either use the bash installer or this package installer i will choose the package installer here because it's quite straightforward and i will use python 3.7 here as the default python version that should get installed so make sure you click right here or in windows you click right here for 64 or 32 bit so i download the 64-bit version and once the download finished you can simply double-click this package file we downloaded and then simply click yourself through this installation guidelines here so continue continue continue yes i agree and here i will select install on a specific disk and install it on my well machine right here so i'll simply select it right here i will choose the default folder so i won't change anything right here click continue and well install right here now we have to wait a few seconds and with that we are done we can move it to the trash and now we are ready to get started actually and how can we get started well as i said miniconda doesn't come with a graphical user interface so we have to use the terminal right here so i just fired up my terminal and if the installation worked correctly we can now simply type conda list if we do that and hit enter then we can see well a list and what does this list include well this list simply shows us all the default packages that were installed when we installed mini conda a few seconds ago so this basically is python 3.7 as you can see it right here and as i said some basic packages which ship with this mini conda distribution no need to dive into these deeper at the moment by the way you can also find mini conda now installed on your system of course this is this mini conda folder right here depending on the path you chose to install miniconda i'm just pointing towards this because we will have a look at this folder structure in a few seconds once again so we have conda installed and we have all these packages here but actually we want to work with environments for that we can simply type conda and and now enter list once again we with conda list we had a list of the packages we've called the end list we get guess what a list of our environments that we have at the moment we only have the default environment this base environment right here and we are currently working in this environment indicated right here now the thing is that this environment will be chosen by default now let's say i want to keep this environment unchanged and now i want to create different environments to well install my different packages in there before we do that let's have a look at the theory once again and then see how this works in practice so at the moment we basically achieved this right here we have conda installed on our machine and let's say we want to keep our base our default environment unchanged and we want to install this pi torch package to do some awesome machine learning stuff for that i now want to create an environment like this where i can install this package and then i want to have another environment where i can install other packages for example for data analysis data visualization or something like that so basically this package should only be available in this environment and numpy for example should only be available in my other environment so to summarize that we have these two packages that we want to install separately and we have three environments we have our ai environment we have our default base environment and we have our well data analysis data visualization environment so that's the goal what you want to achieve right now so back to the terminal and let's see how we can do this and before we do this i want to highlight the link to this corner cheat sheet that you can find below in the video description because you don't have to remember all the commands you can simply look into that cheat and see how this works if you're wondering how do i know these commands well that's basically the source for these so let's now create this new environment for that we enter conda create dash dash name because we will have to give this environment a name and i will call it ai37 because this will be our ai environment and i want to use python 3.7 in this environment just for demonstration purposes so we can specify python equals 3.7 right here now let's hit enter and let's wait a few seconds and now we can see that the following packages or new packages will be installed in this environment if we now hit yes and hit enter it will take a few seconds to extract these packages and here we are we now created our new environment and you can also see how we can activate and deactivate this environment and before we do that let's have a look at our environmental list right now so we'd enter conda oops.com.list call the environment list right list which shows the packages you remember that so with the environment list we can now see that we have still our base our default environment and this new environment you cannot see the path right here so if we switch to our mini cond folder you can now see that we have this environments folder right here where all of our environments are saved well except for the default environment you cannot find this in this folder that's just a side note so we have these two environments and now we want to use our ai environment for that we just saw it we simply type source activate and now the name of this environment in our case ai37 let's hit enter and as you can see now indicated here in the brackets we are now working in this environment in this new environment so if we enter conda list right now we can see that python 3.71 was installed with the approach just followed so by entering python equals python 3.7 so the latest python version was installed and if we scroll up a little bit right here so this is our default package list that we had when we installed miniconds or the package list that is active in our default environment we can see that here we activate it or we use python 3.70 so with that you can see that we already have some differences in our two environments so with that we created another environment we still didn't install the pi torch package i will come back to that in a few seconds let's now first create our other our well data analysis environment you could say we learned how this works already so we can simply type conda create dash name now the name of our other environment which would be d a for data analysis 3 5 because i want to install python 3.5 in this environment so we simply type python equals 3.5 now if we hit enter it again takes a few seconds and then we will be prompted to proceed so we can see we will install python3.56 so the latest python 3.5 version here so let's proceed and with that we now created our second environment so if we enter a conda environment list once again here we can see that we now already also have our da35 environment right here so this worked fine with that we are basically working in three different environments and if we enter conda list not on the list and if we enter source activate da35 now and conda list we should see that we installed python in the version 3.5 right here so this also worked fine so with that we got our two environments what's missing now are the packages because as you can see right here in our conda list in the dna environment we don't have numpy and actually i would like to use numpy in here let's just say i would like to do that so for that we simply enter conda install numpy like that and hit enter and now it again takes a few seconds but you should be able to find numpy yes he does so numpy wasn't installed by default on our machine but anaconda is aware of the package and can now install it this being aware thing will become important in a few seconds but we'll see that so let's proceed right here and with that we install numpy on our machine and with that took a few seconds we now installed numpy in our dna environment so if we have a look at our packages list right here you cannot see numpy in here in our dna environment but if i would go to our ai environment so activate ai 307 i think it was the name and that's enter conda list you can see numpy is not available in here now as we are in this environment already let's now install pi torch right here because i mentioned the package at the beginning so this is this ai machine learning package so let's say we want to use it in this environment for that i'll again type conda install pi torch like that and hit enter now it will take a few seconds and now we have a problem because for some reason conda is not able to download this package it says something about the package is not available from the current channel and we should we have these current channels and we should we should search for alternate channels so yeah what should we do right now well as you can imagine we have a solution for that because in addition to virtual environments and packages we also have channels right here something that we have to understand and conda but it's not that difficult because basically we are working in conda and we so far used a specific package channel the package channel simply describes the the path or the location where conda looks for the packages that we want to install so if we type conda install package whatever then conda has a certain path it can use to see if this package is available now this looks something like that basically by default we use the default path that is available in conda and if we type something like conda install numpy conda checks this path and says yeah i should install numpy let me have a look yes i can find this package so let's install it no problem here what we just saw is that conda again used the default package channel because we typed conda install pytorch and then it said yeah i have to install well what should i install i have no idea i cannot find that no we can't do that that's what's happening right here the solution for that is the following we don't have the default channel only we can add other channels to conda basically and with that tell conda which channels it should have a look at to see if it can find certain packages we have two options to do so the first one would be to type this right here conda install we know that but now minus c because we want to use a specific channel then we can add the channel name which would be pi torch in our example i will show that in a few seconds and then the name of the package which is all the pi torch so with that we can access this channel and install packages from this channel one time so only after entering this command let's have a look at that approach and before we do that let me dive a bit deeper into these channels right here in the terminal so what we can do now is to show the channels that we have we can simply enter conda config dash dash show channels like that if when i hit enter we can see that we have this defaults channel so far that's basically the path conner uses when we run that conda install command and if it can find a specific package in that path then we are able to install the package if not no chance we get the error from above what we can do now is we can type the code i showed you a few seconds ago and tell conda to look for a specific package in a different channel and in case of pytorch you can find this channel right here down there here we can see that we have to add or use the pi torch channel to install the pi torch package what this means is that if we enter conda install minus c now the channel name pi torch and then the package name which is all the pi torch in that case and now hit enter you can see that we don't have this problem in this case because now we can access this channels or this pi torch channel and with that we are able to install pytorch if yes right here then we will see that the installation takes place and with that we were able to install pi torch now from this channel but the thing is that this was a one time thing we didn't add this channel to our channel list if we go to conda config once again dash dash show channels then you can see that we still have this default channel only because as i said we just told conda to use this channel one time get the package and that's it but we have another option the other option would be to use this command we can again type condaconfig and then we can add a specific channel to our channel list with that this channel will be available by default in conda and this means we would be able to use the conda install command right here so the one we used right there because now conda is able to use different channels to look for specific packages let's also have a look at this option for that we will switch our environment we will now go to our dna environment once again so da35 i think it was it yes and now we will go to condaforge.com condo forge is a different channel a different page you could say also offering python packages but it's a community-led collection as you can see it right here if we go to the packages page right here then you can see conda forge specific packages some packages which are only available on the condaforge channel what does this mean for us if we want to install this a blog package right here if we click on it like that we go to github let me zoom in a bit and you can see that this basically converts any documentation or website into a full-fledged blog whatever we won't use it here but let's say we want to install this package what we could do is we could go to our terminal and now type conda install a block like that if we hit enter we get the error once again as this package is not part of the default channel conda has no idea where to get this package from it simply can't find this package now we can add this channel to our channel list as i said for that we simply type conda config like that now dash dash add channels and now the channel name in our case this is conda forge if i hit enter now this channel will be added we can also see this by typing conda config dash dash show channels like that and now you can see that we have both of these channels right here so we install the condaforge channel additionally to our defaults channel with that i'm now able to type conda install a blog and hit enter because now with this default conda command i am able to check all the channels we have and with that install the packages if they are available in one of these channels still might take a few seconds though and as you can see this is working so let's proceed and let's install this package now not the smallest package as you can see right here at least the installation takes a few seconds but well it is what it is i guess so this really took a while but now we installed it so if we type on the list right here then we have the list of our packages that we installed and right here in the last column you can also see that python gives us back the channel where this package was retrieved from always an interesting information same thing is true by the way if we have a look at our pi torch package that we installed so let's switch back to our ai37 environment and type corner list and right here you can also see that basically this pi torch package right here was retrieved from the pi torch channel you can see it right here that's just a side note another thing that might be interesting about these channels is if we deactivate this channel because this will bring us back to our default our base channel the activate like that then we are in the base channel once again and if we now have a look at our conda config show channels right here then you can see that both of these channels are available here because the channels that we installed are not specifically added to a environment to an environment they are added to conda in general that's where we can access these channels from all our environments and one final interesting thing about these channels there is more to say about that of course but i want to stick to the basics of course if we enter conda config dash dash get channels like that then you can also see that we have different priorities right here this simply means that conda will first have a look at the conda forge channel and after that look at the default channel this also can be important if you have different versions of certain packages available in both channels because in cases where you have a package in both channels and let's say that you have the later version of a package in the lower priority channel kind of confusing here then still the package which comes with the higher priority channel will be installed on your machine i think this goes beyond this basics though i just wanted to mention that and with that i want to conclude this video i think we covered a lot of ground right here we had a look at virtual environments in general we saw how we can use conda as part of the mini conda distribution we also had a look at installing packages in these different environments and we also covered the basics of channels and with that i hope that you got a bit more comfortable with the world of python in here and i hope to see you in one of the next videos bye
Info
Channel: Academind
Views: 88,228
Rating: 4.9522033 out of 5
Keywords: python conda, miniconda, conda environment, conda channel, python environment, conda distribution, python package channel, python environment channel
Id: 23aQdrS58e0
Channel Id: undefined
Length: 26min 10sec (1570 seconds)
Published: Fri Nov 30 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.