Stop using pip! Use Conda instead! (Miniconda introduction)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome my name is Herbert and today we'll be looking at conda or rather mini conda but we're going to be talking about that in just a minute here conda is a virtual environment and package manager and let's have a look at what conda or mini conda actually is so what is conda conda is a package and environment manager which allows the creation of virtual environments it allows to install packages and binaries it allows to set environmental variables settings and more conda enables multiple environments these environments are all isolated and all these isolated environments can have different versions of packages different variables different settings and more now in this video we're going to be talking about miniconder miniconda is a lightweight installer for conda Python and some dependencies it's a lightweight version of Anaconda it only has the essential packages and it has access to the Anaconda repository packages by default now what are the benefits of using Condor well first of all the compatibility is a big one you can run your software on isolated environments that contain the exact packages variables and so forth that you need and you can also install different python versions so that it's compatible with your application it's also a lot cleaner because all of your packages variables binaries and so forth are not installed system-wide so it doesn't make a mess when you install multiple packages or assign multiple variables it also makes the entire process of developing a lot clearer and easier because it's a lot easier to differentiate between your projects since they are all in different virtual environments which makes the entire development process a lot more streamlined first of course before we start we're running on our Ubuntu system here and we just want to make sure that Ubuntu and python which will be upgraded with the upgrade as well is upgrade it to the latest version so right now I've already done this so if I do Python 3 dash dash version we'll see that I'm already on 3.10 which is a this version as on this date which is the which is the 21st of Feb of January this is the latest version that you're going to be getting uh from apt but you know that might change in the future and of course right now python is already on 3.11 I believe uh I don't know I think it's still in beta but it's definitely already a 3.11. so this is definitely not the latest version but to really get the latest version of python it's a really difficult process or you know you either have to get the version from their website and compile it yourself or you need to add something uh a different repository uh to your pro to your repository list and then you can get it from a different repository uh but you know it doesn't really matter all that much we don't really need the latest version of python for this to work if you really need the latest version of python then I guess that you still need to get it somehow but for this specific case we really don't need late the first latest version of python because at the end of the day conda is going to be managing our uh Python binaries and when we go over to the conda website over here we'll see that conda is uh released with python 3.10.8 which is a little bit above what we have but it doesn't really make a big difference but anyway we're gonna be going with this version here and you know there's different versions if you don't want to work with 3.10 that's fine you can get the installer for 3.9 8 all the way oops these are the windows installers so you can get a python 3.10 all the way down to 3.7 I think there are older installations as well but I don't think that you want to go with 3.6 because I don't think that it's a supported anymore so I think uh you're better off just getting the latest version uh or you know if you really require a specific uh python version you can go down here and get that one but for this video we're going to be going with the latest version so go ahead and copy the link address over here now let's go back into our virtual machine and we're right now in our home directory which is where we're just going to be putting this uh shell shell script so go ahead and do wgets and then just uh that's not the link we want we want copy link address and then we'll paste that in here so we're going to be downloading that shell script and then we're going to be running it on our system okay so we downloaded it and now we have to run it so let's just go ahead and do sudo bash miniconder 3 latest which is the shell script we just downloaded uh I want to do sudo because you know I don't like putting this in my home directory you'll see in just a minute why we're gonna do sudo uh so there we go and then we'll do kind of do enter and just scroll down here and then accept this by typing yes and now it's going to ask us where we want to install mini calendar and you know by default since we are running this as sudo it's gonna assume that we are the root user and it's going to want to install this in the root user directory that's not what we want that's not really a good place to put that because only root has access to it and we want to make sure that everybody has access to it um you know everybody should be able to read the binaries not everybody should be able to change anything in that directory but everybody should be able to read that and a perfect location for that on let's say Ubuntu is the opt directory which is a location where you would install optional software which is what minicanda is in my opinion so uh miniconder three and this is going to be the location where we're going to be installing mini conda or we're going to be installing calendar rather but we're just going to be calling it mini conda since the installer is called miniconda so opt uh Slash mini condo there we go it's unpacking now also you know uh you might have noticed that I used explicitly bash I did explicitly say bash because the shell script uh the default shell interpreter in that shell script is not bash so you really need to Define that bash in front of that script and make sure that you don't go ahead and do the usual stuff you know change the permissions to make it executable and then run it with DOT forward slash no you really need to specify bash or I haven't experienced it with that yet but you could maybe change that shell interpreter on top of that shell script but there's some binary stuff in there so I wouldn't mess around with that shell script too much and I would really just run bash run it with you know bash in the in the command line now over here it's going to ask us if we want to run conda in it uh we don't really want that it's not required but we're gonna try with yes and you'll see that it doesn't really make any difference the reason is because because the shell script is thinking that we are the root user since we ran this with pseudo privileges it's going to be using the bash RC file in the root directory it's going to be well it's going to be changing that bash RC file in the root directory but we are not root we are Ubuntu Ubuntu is our username so we want to make sure that that conda init is actually executed in our directory and not in that root directory we needed those root privileges because the opt directory uh well actually if we do LL of the root directory well the the the root not the root directory but you know what I mean the the root of the up of the file system we'll see that the opt has read write and execute for the root user but it does not have any write permissions for anybody else now it's World readable so everybody on the system can read from that and that's good because we just need that binary but because our conda in it was not executed for our user we're gonna need to do some trickery here so let's go ahead and make a Sim link from this opt mini conda directory and let's create a new one in the user forward slash bin so that will make sure that if you don't know what a Sim link is it's basically like a shortcut we want to put this binary here this combo binary in the user forward slash bin directory because that is where our path or you know whenever your shell is looking for executables it's going to be looking in directories that you specify in the path and this one is not specified in a path we could add that to the path as well but I think it's just easier to have just a Sim link that just redirects you to that directory or to that binary here so that's what we're gonna do we're going to be getting that opt miniconder 3. inside the directory condom bin we're going to find the binary conda and we're going to be creating a Sim link inside of the user forward slash bin directory and that Sim link is going to be named conda so go ahead and do that and now we are Ubuntu and now we can do Kanda init Bash and that should basically do the same thing so we see that the same conda init was executed but now we can see that it modified our bash RC file and that's exactly what we want to use right now so let's do source this one over here so forward slash home RC and when we execute that our shell changes a little bit so we now have base and this means that we are in the base virtual environment of Kana and which means that we are not really in a virtual environment yet where we basically are but we didn't create one this is the base one this is the default one this is the place where you don't want to be installing packages and stuff like that because this is like the system-wide virtual environment it's not really meant to be installing specific packages unless you really want those packages to be available to the entire system so we're in this base environment but we want to switch over to a different environment right we want to create our own environment well we can do that with conduct create dash dash name and then we can define something like flask app and uh if you don't specify this it's basically not going to install any version of python in your environment so you need to say that it needs to install python and also we can Define the version so we're going to do something like python equals 3.9 if you don't specify this it's just going to if you just do python it's just going to be downloading the latest version it can find so or installing the the latest version it can find so we run this with python 3.9 for example and this will create our environment it's going to be installing a bunch of stuff here so it's going to be installing sqlite python pip all those good things also do take note that conda does track pip packages so if you're installing things through pip you can perfectly do that in conda conda keeps track of those packages as well so proceed yes there we go and then it says we can activate this environment by doing can't activate flask app let's go ahead and do that and now let's see here python dash dash version which is the latest version of 3.9 and also if we do which python we should see that it now points to our.comvs and that binary is now in our environment and we're going to look at how we can change this directory because by default it's over here which is a good location you know it's it's not bad you know it's just a hidden location dot condo you can't really uh see it if we do just do LS we'll find this but if we do LS minus La for example we'll see that that conda environment is here and we can go into that directory and find our environments over there but you know we don't really need to be in there for for any reason uh it's just all done automatically by conda there's no real reason why you should be in that environment directory unless you want to change a few things later on and so now we want to install a package let's just say we want to install flask well easy just do conda because we are right now in our flask app environment we can do conduct install flask and then it will install the latest version of flask so let's just do yes here by the way you can also do something called conda search flask for example that would search the uh the repository for flask packages and it will just show you a list of available packages and those packages will include all the different versions that it has so so flask and you can start all the way from 0 12.2 all the way up to uh 22.2.2.2 so if we do come the list over here and we would grip on flask now we'll see that it installed indeed the latest version which is 2.2.2 great okay so installed flask now let's try create a flask application let's do Vim and let's just call it main.org let's just call it Hello dot pi hello.pi and now let's go back in this let's go over to this website over here which is the flask quick start and let's just copy this here and this is just a basic quick start a minimal application that is on the flask quick start website I will just copy that in here we press I and then we just copy that in here we escape and then we write WQ to write this and now we can run this app by doing python minus M flask Dash Dash app and we're going to define the app which is hello we named it hello.pi so we're just going to call this app hello run and then we Define the host so it listens on all the interfaces if you don't do this it only listens on localhost and we want this uh to be available uh we want this to be available to the internet right we want this to be listening on all interfaces so we can access it from outside let's do this and now it's going to say oh this website is running over here so we can copy that link or we can go over here and we should see our application which says hello world which is just like like I said it's a basic application it's not really very fancy but it it's just to show you how it works okay so let's quit now and let's do another conda deactivate now let's try to run this again so we are in our directory and we do see this hello.pi so we know that that application is in here so let's run that again so let's go back here let's copy this command again there we go and now it should say there's no module named flask because that module is only installed on our virtual environment that we just created it's not available anywhere else unless we would install it in this base environment it would be available in the base environment now remember when I said that we can have our own conda environments directory first of all we're first gonna need to create one so let's do MK there and let's just call this conda envs and now we can run this command so we can do conda config dash dash add envs there's so make sure that you spell this correctly so it's envs plural there's also plural and then we're going to define the directory that we want to put this in so we just created this directory called conda emvs in our home directory so this command should execute without any issues there we go and if we do now conda create uh dash dash name and we'll just call this test123 and we're just gonna be doing yes here and take note of what it said here so environment location is going to be taking this conda slash envs directory as our default directory so if we go in here we should see that our environment was created in this directory instead so of course this is a very very basic overview of how to use conda but it just gives you this idea of how you can really split up your environments and have different packages in different environments and this makes it so that you can run these environments on one server and split that up into multiple applications without them interfering with each other now of course flask was a basic application and you know if you really want to run a flask application in production it's not going to be as easy as we did it because you're going to be needing special servers and you're going to be needing to specify different ports that it wants to listen to if you really really want to split up these applications but you know you get the general idea you just have different virtual environments and in these different virtual environments you can store different packages so that you can make sure that your application runs on one specific environment and that environment has a specific version in which you wrote that application so when you're really writing an application you might want to specify something you might want to specify your packages self now when you're developing an application you most likely write that application in a specific version and you want to make sure that that version is always the same well the way you actually can tell Kanda to use a specific version is by doing like conda install and then you do flask equals 2.1.3 for example you can really specify the version over here but you know the easiest way to do so is by creating a requirements file so let's go ahead and look at this requirements file that I wrote which is in a yaml format so we're going to be defining the name of our app which is flask app and then it's going to be called dependency and then the next key is going to be called dependencies and then the value of that will be a list of packages you want to install now this is yaml format so make sure that you write it correctly because this is really really sensitive so you want to do two spaces Dash a space and then you want to define the package over here so all the rest can be you know on its own uh independent line and then when you create the list underneath dependencies you can create this list like this and if you want to add something else down here you want to do again a dash space and then another package over here but for now we're just going to be doing one package and I'm going to be writing and quitting that firstly to go into Kanda activate flask Dash Dash app flash flask app now we can run this again I don't know if it would do it because we did specify the the content environment but you know just for safety purposes we're just going to be going into that fast map so conda EMV update.file requirements.yamo the yaml 5 we just created let's run that and now we should see a lot of stuff here and now let's do this again let's uh do a conda lists and let's do grep flask and now we see that version 2.1.3 is installed which is the version that we defined over here so conda has installed it now also we can do something easier so let's do condo deactivate so also you can Define this right from the get-go so if you want to do conda create dash dash name and we want to do something like um a hello there or like hello just name it hello and then we want to specify something like flask equals 2.1.3 and then python equals 3.9 for example that would also work perfectly fine because we're defining the um we're defining the packages that should be installed right from the beginning so right over here we're telling it to create this virtual environment and then also after that we're telling it to install flask with version 1.2.1.3 and python with 3.9 and if we scroll down here we should already see flask is in here and it's going to be installing python again so we do yes okay so we're going to be doing conductivate hello and now we're going to be doing a conda list grip flask again and that should also give us that uh version over here and also python should already be installed python-version which is 3.9.16 so that was about it for introduction into conda uh we're going to be using this a lot well I'm going to be using this a lot in my projects so if you want to see more of these python projects I'm going to be doing projects with python with bash and they're all going to be focused around devops and system administration and things like that so if you want to join me in those projects then this is a very good start also for bash for example if you want to become a devops engineer or you want to become a system engineer and you want to learn more about bash I have a full course on the beginning basics of bash and there's going to be a good basis for you to start with batch scripting so on this channel we're going to be doing a lot of python scripting just some some cool projects that you can do to practice your skills in devops and in system administration also going to maybe you're going to be doing some other development things I don't know we'll see we'll see what we do but definitely know the focus is going to be mainly about Automation and devops and things like that so again this is a good place to start really practice using conda try to avoid using things like pip and installing system-wide packages you really want to split those virtual environments up into different segments so that each application has its own little space its own little virtual environment to run inside of and that's going to give you a much better experience and it's also going to be a good thing to practice when you really want to become a developer or a system engineer or devops engineer whatever you want to call it having those virtual environments is really going to be crucial for you to make sure that all those applications that you're developing are running smoothly and they are not conflicting with each other so that's about it for me guys thank you so much for watching again if you want to see more of my videos and if you want to follow me with these projects that I'm going to be doing give me a follow give me a subscribe hit that like button and thank you so much for watching and I'll catch you in the next one bye
Info
Channel: Herbertech
Views: 10,400
Rating: undefined out of 5
Keywords: the it guy, herbertech, python anaconda, data science, data science course, python conda, anaconda python, install anaconda python, mini conda, conda install, conda tutorial, install anaconda
Id: lBXDOY6ZtBg
Channel Id: undefined
Length: 23min 22sec (1402 seconds)
Published: Fri Jan 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.