Getting started with Anaconda and Python on a Mac

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's learn how to set up Anaconda for python on a Mac computer if you're new to Anaconda I have a previous video that talks about what it is and why you might want to use it if you're working with python this video is just going to be about the procedures of setting it up and by the end of the video we're going to run our first Python program using Anaconda to get started I'm going to go to anaconda.com download it detects that I'm on a Mac so I'll click the download button and I could choose which processor I'm using uh newer Macs are going to be the M processors older Macs might be running Intel so the download is complete I'm looking at my downloads folder you could see the uh package installer so I'll double click that I'll Grant permissions to run the installer this first screen explains what's going to be installed I'll click continue here's some more general information you can skim through but I'm just going to proceed forward and click continue we'll agree to the software license this is some information about where this is going to be installed on my computer I'm going to leave it all as the defaults and click install when it asks for permissions we're just going to say okay okay and we'll give that a moment to finish and the install has completed and you could see that anacon Navigator launched in the background so to finish the install process we'll just say continue and then close we can move the installer to our trash and let's do a quick tour of the Navigator which is anaconda's graphical interface for working with the features that Anaconda provides uh here on the home we could see a bunch of supplemental programs we might find ourselves using when working with python uh for example uh spyer is a very popular uh code editor used often in scientific Computing uh for my purposes I like to use VSS code which is a more general purpose code editor but it definitely has all the features we need to work with python and this is something I'm more comfortable with but by all means choose the code editor that you're most comfortable with if you want to work with Jupiter notebooks which are a great way to share and document python code you could launch that from this homepage and you could skim through the other options that are provided and see what other programs you might want to check out but I want to skip over to the environment section this is one of the key features we get with anakonda is the ability to manage different environments which allow us to set up workspaces uh where we can customize the python related software we're using for a given project and to visualize this I'm going to pull up a graphic that I shared in the preface video to this video where I talked about what Anaconda was in general uh and what I'm showing in this graphic is just a visualization about how when you're working on different project types you're going to have different soft Ware needs there's going to be different python packages you're going to be using you might even be using different versions of python and by working with environments you can create these isolated containers for those different projects so you don't have uh packages or version numbers that are conflicting with one another uh it also makes it easier to collaborate with other developers because you can actually share your environment so a colleague can have the exact same setup for a project there's lots of benefits to working with environments and anacon it makes it really easy to manage them now when we're in Navigator here in the environment section we're looking at a visual interface for managing our environments and you could see that we start off with a base or root environment we have the option to create new environments we could import environments back up remove all the things you would expect uh and then for a given environment we can see all the packages that are included with that environment now a benefit of anaconda is it comes pre-loaded with a bunch of packages that are really useful in the world of scientific Computing and so when you're skimming through through the base or root package you're going to see a lot of those packages listed here so we could just start working within this base environment but generally speaking anytime you're starting on a new project it's a good idea to create an isolated environment for it and pull in just the packages you're going to need in that project now when it comes to creating environments you have a few different options on how you could do it uh via the Navigator we can just simply click uh create give our environment a name we could choose the version of python we want and then once it's created we could use the Navigator interface to search for an import the packages we're going to need so that's option number one option number two is we could switch gears to command line and we should have access to a commandline program called cond that came as part of our Anaconda install and this is going to give us access to all the things that we would do in the Navigator when it comes to working with environments and managing our packages we're just going to be doing it via commands um and if you're not someone who works a lot in command line this might seem a little counterintuitive why you work with commands when you have this nice visual interface the reason is is because at the end of the day you're going to get a little bit more power and customization with the command line version and also just as programmers we spend a lot of time in the command line anyway so uh it's a place you're going to want to get comfortable even if you haven't spent a lot of time there yet so understanding that let's get familiar working with the cond tool first thing we want to do is create an environment we're going to do that with the cond create command we're going to include a flag called D- name and we're going to name our environment I'm just going to call mine demo we're going to confirm the the location where this environment is going to be installed so I'll just type Y and hit enter and then following the instructions it gives us we can activate our new demo environment with this command and now you can see that our prompt is preface with the name of that environment just reminding that that is the environment we're working in the first thing we want to do in this environment is install python so when we're installing outside packages in cond we'll do that via the cond install command followed by the name of the package in this case that's simply just going to be python this is telling us about some other packages that are going to be pulled in that support python so I'm going to type Y and hit enter and with that complete we can confirm the install by running the command cond list in this case we want to list the details for that python install and you can see version 3.2.2 was installed which is the latest version as of this recording uh if for some reason you didn't want the latest version of python when you installed it you can include the version number as part of that command the other thing we could do at this point just to highlight how environments work is if we run the command which python this is going to tell us which install of python our computer is currently locating all right you can see it's finding the version of python that's installed in our Anaconda environments specifically within that demo environment but watch what happens if I say cond deactivate that's going to get me out of the demo environment so you can see my uh prompt here is no longer indicating I'm in demo and if I run which python again you can see it's found a completely different install of python on my computer and if we run the command python version you can see it's actually an older version of python so hopefully this emphasizes what environments do it allows us to really pick and choose which software is running in a given context uh and have full control over it and also vary it across different environments all right so let's get back on track let's get back to our demo environment so once again we're going to run cond activate demo and then within this environment we want to create our first python script and run it so I'm going to actually switch gears over to my code editor since I'm going to be doing some coding now so I'm going to bring up vs code which is uh my code editor of choice but you could do this in any code editor and what I'm going to do is just uh create a new python file so I'm just going to save this on my desktop I'm going to call it demo. py anytime you're creating a python file it's always going to end with a piy extension so we're going to save that there and just to get us started we're going to do a very simple python command we're going to say print hello world just to show that we could get this running all right I'm going to save those changes and then coming back to command line to run it I'm going to switch over to my desktop and I'm going to run the command python followed by the name of the file I just created so that was demo. piy and perfect you can see it's outputting that hello world string so that's a good proof of concept but let's make this a little bit more interesting I'm going to go over to the notes that accompany this video and I have an example python script we can run down here under the heading run example program I've got a chunk of code I'm going to click copy bring that into my code editor and put that in my demo. file and what this code is doing is some basic web scraping so it's going to go to acuweather.com and load the weather for this given location and then it's going to scrape from that content just the current temperature for that location um now the reason I wanted to set up this example is because it uses two external packages to accomplish this the first is something called requests it's going to use that to actually make the request to acuweather.com and then we're using a package called Beautiful soup that's what's going to be parsing the content we're getting from Acy weather to extract just that temperature all right and this is very common uh thing you're going to see in Python scripts where at the very top you're importing some external packages or tools that you're going to be using and then you have code that utilize them um now in order for this to work I need to make sure that my environment has access to these external packages if I try to run this right now we're going to get errors and just to show that let me go back back to command line we're going to R again run our demo. py script and you can see it's uh hanging up on that first line where we're trying to uh pull in this package or module called the request it doesn't see that in this environment all right so to fix that once again we're going to say cond install and we're going to say request that's the name of the package we're going to be pulling in we'll say yes to proceed with the install and then we'll do the same thing for that beautiful soup package and then with those packages installed let's run our script again and perfect there's our output we were able to extract the uh current temperature from acuweather.com for this location so hopefully that little example just gave you a snapshot of the kind of thing you're doing when you're working with environments in Python where you create an environment you pull in the specific packages you need for that environment uh and then of course you build your Python scripts to utilize them now in that example I just told do the name of the packages we were using um if you are looking for packages uh there's a couple different resources you can check out the first is cond via cond but with that I'm going to wrap up this example and the less thing I'll leave you with is just a quick note that if you go to the end of the notes that I company this video I have a quick reference sheet of some common cond commands you're going to find yourself working with as you're managing your environments and your packages
Info
Channel: Susan B.
Views: 2,349
Rating: undefined out of 5
Keywords:
Id: V4riykgUS94
Channel Id: undefined
Length: 11min 7sec (667 seconds)
Published: Tue Feb 27 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.