Setting up a Python Development Environment in Sublime Text

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there how's it going everybody in this video I'd like to walk through how to set up a Python development environment in sublime text now I get a lot of requests to show how I have my development environment set up and also what packages I have installed and what settings I use and also how I run Python from within sublime text now I've actually done a basic walkthrough of setting up sublime text in a previous video but that's actually more geared towards web development back when my full time job was doing front-end JavaScript work now that video is also pretty old now and there are a few things that are now done differently so I'm just going to completely uninstall sublime text and walk through the entire process from scratch and this time instead focusing on setting up an environment for Python development so with that said let's go ahead and get started so I've already completely deleted sublime text from my machine and now I'm over here at the sublime text 3 download page now the first thing usually people ask me about sublime text is whether or not it is free and you can see here on their download page that sublime text may be downloaded and evaluated for free however a license must be purchased for continued use and there's currently no enforced time limit for the evaluation so basically what that means is that sublime text is free to download and use for an unlimited amount of time but if you don't purchase a license then you'll occasionally get a notice asking you to make a purchase so I've personally bought a license but it's not 100% necessary so you don't need one to do this walkthrough let's walk through this video or to use sublime text for as long as you want ok so let's go ahead and download sublime text so I'm going to download this for my operating system and I'm on a Mac but if you're on Windows or Linux then you'll want to install the version for your system ok so now that is finished downloading I'm going to go ahead and open this and on a Mac I just have to drag this into my Applications folder but on another operating system you might have to walk through a quick installation ok so now let's go ahead and open up that fresh installation of sublime text now I have a sample python module here that I'm going to use just so we have something to run within sublime so let me go ahead and drag this over real quick okay now I'll just go ahead and maximize this here and open up this test module so this is a sample class that I used for my object-oriented series now if you don't know what this code is doing then don't worry about it I just wanted something that we can run within sublime and also something with classes and functions so that we can see the difference between the different color schemes so let me go ahead and make this big enough so that everyone can see here okay so at this point you can run Python programs using the automatic build system so if I wanted to run this code then I could just come up here to tools and if I wanted to see the build systems and I could just hover over that and you can see that it's set to automatic now I don't really use the automatic build system anymore but we'll get to that later now if you wanted to try to run this Python code then you could just come down here to build and if you're on a Mac then you can see that the shortcut for that is command B so I'm going to go ahead and run that now with this automatic build system mine has some weird characters here at the top and that's because it has a conflict with one of my dot files you can just ignore that because you're probably not going to have anything like that but it does run the code from our file here at the bottom and like I said that yours will most likely just run the first statements without all that other junk at the top but I'll talk more about build systems towards the end of this video okay so this is just a basic fresh installation of sublime text where we can run some simple code so let's go ahead and customize this a bit and add some extra functionality so I'll show you how I set this up and how you're used to seeing this in my videos so first of all we're going to want to install package control now it used to be that you had to do this manually and copy and paste a long command into your sublime text terminal but after one of the updates I'm not sure which one but they added the ability to do this directly through sublime text and I'm sure that they did this because package control is so popular and they wanted to make this as easy as possible so package control allows us to install third-party packages that add functionality to sublime text so we can up open our command palette by going to tools and then clicking here on command palette and the shortcut on the Mack you can see here is command shift P and I'll probably use that shortcut for the rest of this video now once we have that command palette open then let's just type in install and you can see that the top option here is install package control so let's go ahead and click on that and if we wait for just a second there then it should pop up with this package control was successfully installed pop-up once that is finished so let's go ahead and exit out of that okay so after you get that notification we should be able to install packages so let's open up that same command palette as before so on Mac that was command shift P and now let's just type install and you can see that the first option here is install package so I'm going to go ahead and select that so the first packages that I'm going to want to install are my themes and color schemes that I use now if you explore around different packages then you might notice color schemes and themes the difference between a color scheme and a theme is that the color schemes change the color of your syntax and things like that and the theme changes the entire look and interface of sublime text so if you like this interface but just want to change the color of your code then you could try different color schemes but I've been using the same theme and color scheme for some time now and I really like that and you can look around at different ones to see what you like but a color scheme that I like is called pre-dawn and the theme that I like is called material so I'm going to go ahead and install both of those so to install pre-dawn I'm just going to type in pre-dawn here and you'll see that that pops up as the first option so I'm just going to go ahead and click on that to install it if you look in the bottom left you can see that it says that it's installing a pre-dawn so most of these packages install pretty quickly now after you install a package then some of them pop up with these readme files giving you more information so you can see here that this theme popped up a readme and gives us some activation instructions and additional recommended settings and things like that now I'm not only going to be using the pre-dawn color scheme and not the entire theme so to install the theme that I'm going to open up my command palette again and install another package and this is called material theme so if I just type in material it doesn't pop up all the way but material theme is the one that we want and now that's the top one here so I'm going to go ahead and install that okay so that material theme has finished installing and it usually pops up a another readme file just like the pre-dawn readme but for some reason it didn't this time but that's okay because I'm going to show you all the settings that I personally use and I've kind of mixed and matched the recommended settings for both of these packages and also have some additional settings that I personally like to have set as well and I have these available on my github page and I'll put a link to this in the description section below a lot of people have been asking me to put more things up on my personal github page lately so I'm going to try to start putting everything up there so if I pull up my github page here I've already got it pulled up here within Chrome and so my sublime text settings are a little Barry's down here and my dot files and NIT folder but like I said I'll have a link to this page directly in the description section so the first settings that I'm going to change here are my general sublime text settings and these are located within this Preferences dot sublime settings file here so I'm going to go ahead and click on that and I'll go over these in a minute but for now I'm just going to go ahead and copy all of these and place these into sublime so I'm going to copy those and now within sublime text I'm going to click up here on sublime and then preferences and then settings now that's how you get there on a Mac I believe on the windows those preferences might be under the file but I'm not entirely sure now when I open up the sublime settings it opens up two different files here and this confuses some people so on the Left we have our default settings and on the right we have our user settings now you only want to make changes to the user settings because the default settings can get overwritten when we do updates and things like that so within my user settings over here on the right I'm going to go ahead and erase everything and then just paste in what I copied over from my github page okay so now when I save these settings then you're going to see the theme change the entire interface so if I save that then you can see that that entire interface looks different now now usually after I make a lot of changes to any settings I usually like to restart sublime text just to make sure that all those changes take effect so let's go ahead and quit out of sublime text and then open this back up and we may need to quit out of these settings and reopen those when we open sublime text back up to okay so now let's go over some of these settings that I set and like I said these are my personal preferences so you can tweak these any way you like now a few of these are suggested settings that came with the packages so for example here we have the theme is set to material theme and I like the darker theme for that and the color scheme like I said is that pre-dawn theme and then these are just some additional theme settings that I like to have set here the graphite color and the compact sidebar now for the font face I use source Crowe Pro and that is available for free on google fonts and I'll leave a link to that in the description section below as well now I have the font size set really large because I do these videos but when I'm working on personal projects I usually take that down a bit okay so I'm not going to go over all of these but let's see if any of these really pop out to me here so this scroll past the end I like to have that set to true because if that's not set to true then once you get to the end of a file then it doesn't let you scroll past it kind of like over here let that set the true it just lets you scroll past and I find that useful I'm also here I have my translate tabs to spaces set to true and that's just so everything stays consistent even when I use tabs now I've got my show definitions and show errors and line set to false because I don't really like things popping up and getting getting in my way when I'm coding now if you want more of an IDE type of feel and maybe you want those set to true okay so that's a quick look on my sublime settings now you can always go over here to the default settings and look at everything that is available for you and also they have a lot of good comments here that show you what those options mean so if you want to read through there then you can figure out if you want to you know change some of these round around to your own personal preferences okay so now let's go ahead and get moving along and installing some more package and some of these we're going to move through fairly quickly so I'm going to close that down and now I'm going to open up my command palette again and like I said before you can click on tools and command palette or you can use that keyboard shortcut now I'm going to type in install package now one package I like is called bracket highlighter if I type in bracket we can see it down here bracket highlighter I'm going to install that and after that finish installing it will pop up a small readme now basically what this does is it helps you keep track of where certain brackets begin and end so if I have a set of brackets up here that spans multiple lines then you'll see when I click on the opening or closing brace it'll show you the other brace over here and the gutter where that begins or ends and it's extremely useful in languages that use a lot of braces like JavaScript but I find it useful in Python from time to time too especially since it underlines the other bracket so you can more easily see if you haven't closed something off properly or not so now let's go ahead and get rid of those and install another package now another package that I find useful is sidebar enhancements now if I do a secondary click over here in my sidebar without this installed then you can see that the options are pretty limited we just have new file new folder things like that so now let's install sidebar enhancements and once that's finished installing if I click over here and do a secondary click in my sidebar now and you'll see that we have a lot more options for searching and opening files and things like that and I find these new options very useful okay so now let's install a package that's a very Python specific so this adds a lot of Python functionality to sublime text now this will allow you to set up code linting and auto formatting the ability to jump to function definitions and things like that now this package is called let me in click install package and this package is called anaconda so I'm going to go ahead and install that now this is different from the Anaconda Python distribution from continuum analytics this is just a sublime text package with the same name so let's install that and I'll show you a few of the specific settings that I use with that anaconda package now if you're ever unsure if you're installing the correct package or not then a lot of these have links to the github pages as well so you can always go to those pages to make sure that you're installing what you think you're installing okay so now that we have this installed let me show you some of the settings that I use specifically with this package now I'm going to pull back up my github page here and if I go back a page and you can see that I have anaconda sublime settings here as well so I'm going to go ahead and click on that now there's a lot less personal settings that I have here than my general sublime settings so I'm just going to go ahead and do the same thing and copy these and now we want to access the anaconda settings within sublime text now to get here we can go to sublime preferences package settings anaconda and then within anaconda I'll go to settings actually I'm going to open up settings default and then I'm also going to go to that same place preferences package settings anaconda and I'm also going to open up the settings user now I'm going to go ahead and set someone Tex and to split screen mode so that we can see both of these and on a Mac that is command option 2 and I'm sorry I'm not sure what that keyboard shortcut is on Windows now just like with our general settings we don't want to change the default settings we only want to change our user settings because the default settings can be overridden when we do updates and the user settings will always remain what we put in that file so we want to make our changes to the user settings so the user settings are currently blank so I'm going to go ahead and paste in what I got from the github file and then I'm going to go ahead and save those now just a quick side note if you want to change settings for any other packages then the same place that we located the Anaconda settings that's where you can locate settings for other packages as well and those were within package settings but anaconda are the ones that we're going to change right now now just like my general settings when I save a lot of changes to the settings I usually like to restart sublime text just to make sure that everything takes effect correctly I don't think you have to always do that but I do it just in case okay so we just restarted that now let's go ahead and take a look at the settings now there isn't a whole lot here basically I'm saying that I want Auto formatting turned on and what this does is it will auto format your code to be pet bait compliant if possible I like this because it keeps my code consistent so for example if I go here to my test module and I put some extra lines here between the methods and the properties and then I save this and you can see as soon as I save it it formatted back to the proper pep eight compliant settings there okay so back to the settings I also have some Auto formatting ignores in here now I actually don't remember what III o.9 is but I do remember that the e 501 is for maximum line length allowed now I probably should keep my lines shorter when coding but I go over that limit a lot and I don't like warnings to pop up all the time so if you have any auto formatting or pet bait warnings that you want to ignore then you can just put those within the auto format ignore and the pet bait ignore now really other than that I just have some lender settings here that are turned off now the reason I have those turned off is because it already marks the errors and the gutter and that's good enough for me and also you know this is less intrusive with these turned off so what I mean that it marks those in the gutter so let's say for example that I make a for loop here so I'll just do for num in and then do a list of one two three four and I'm going to forget to put a colon here and then I'm just going to print and instead of printing num I'm going to print n so I'm going to have the wrong variable name there and I'll save that so you can see with the linting that this anaconda package provides that it pops up with a ball here and the gutter telling me that something looks wrong now if I click anywhere in this line and look at the bottom left I'm sorry if this is a little small for your screen I don't know how to make this larger but down here it says invalid its syntax now after looking at that line for a little bit then you'll probably notice that the colon is missing so we'll go ahead and add that in and save it and now the warning that pops up down here is that we're supposed to have another line in between our class and the rest of the code so it's go ahead and save that now we have one more ball over here in the gutter and if I click on that line then it says undefined name in so then we'll realize that all instead of in that's supposed to be none and then when I save that you can see that the rest of those go away so it's nice having that linter watching everything in the background because we all make dumb mistakes like that and it's nice to have something that points those out now the reason I opened the default settings for anaconda here is just like with the general sublime settings it's nice to be able to look through all of the options that you have available and also all the documentation of what each of these options do so you can read through and know exactly what changes will do what and like I said these are just my personal preferences so I'd recommend you come in and kind of you know read around and try some different things for yourself and you know set this up how you prefer to have it set up in your sublime text okay so now that we're done with those settings I'm going to go ahead and make this non split screen again and to do that I hit command option and one to make this one pane and now I'm going to go ahead and close down all of the other windows or tabs that we have open here and just have my test module here now as far as the packages that I install that's basically it now I also mentioned that I'd go over build systems real quick and I think that if you're going to be working on multiple projects then you should become more familiar with how these work now like I said before this is currently set up as the automatic build system which runs your script with a default Python on your machine but if you want to use different versions of Python or virtual environments then you'll need to set up multiple build systems now I'm not going to go in depth about build systems in this video because I have a video specifically about build systems and I'll link to that in the description section below but I will show the quick process of how to set up a basic Python version 2 and Python version 3 build system now I also have these available on my github page as well so I'm going to go ahead and pull those up and go back and you can see that I have a Python sublime build system for Python 2 7 and 1 also for Python 3 5 I'm going to open these both up and their own tabs so you can see these files are very small and this one has the path to python 2 7 and this one has the path to python 3 5 now like i said i'm not going to go in-depth as to what these build systems do i have a separate video on that but for now i'm just going to go ahead and copy this code from this Python to build system and now within sublime text I'm going to go up here to tools and build system and then down here to new build system and now look in here I'm just going to paste the code that I grabbed from the github page now within here I'll go ahead and save this and I'm going to save this as Python 2 7 dot sublime build now be sure that you leave that sublime build extension on there you don't want to accidentally remove that so I'm going to go ahead and save that now this pop-up that I just received here now these are what you'll get from time to time if you haven't purchased a license for sublime text so like I said you can use sublime text for an unlimited amount of time but if you don't purchase a license then you'll get these pop-ups from time to time so for now I'm just going to go ahead and hit cancel on that okay so now we just created our Python 2:7 build system now let's do the same thing for Python 3 5 so I'm going to open up my github page here and copy those settings for the Python 3 5 build system then I'm just going to go through the same process I'm going to go to tools build system new build system and paste all of that code in there and save that now be careful not to overwrite the sublime build extension we just want to call this python 3.5 and save that so now that we've saved these build systems then we can go to tools build system and now we have this Python 2 7 and python 3 5 build system in here so if I choose this Python three five build system and now if I run my code here within sublime text now you could have gone to tools and build but I just use the keyboard shortcut for that you can see that now when we run our code now we're running this user local bin Python 3 5 and when we print out the version it says 3 5 and then it also runs the rest of our code down here at the bottom now like I said I do have a full video on those build systems so I would suggest watching that if you need to use Python from a specific virtual environment or anything like that ok so that basically does a prowl I set up my Python development environment now one more thing if you do experiment around with different packages and you don't like one that you've installed then you can easily remove a package by opening up your command palette so I'm going to do that with command shift P and instead of installing a package if you type remove and you can see remove package down here as well and if I click on remove package it'll show you all the packages that you've installed and you can remove any of those that you try out and end up not liking ok so I think that's going to do it for this video now this is everything specific to my Python development environment now if you look at the github page that I linked then you'll see that I also have some personalized keyboard shortcuts in there as well but I thought that those were you know so personal preference that no one would be too interested in those but if you'd like to see those shortcuts then you can view those you know at the same github page that I have linked so if you'd like to see some more videos on optimizing sublime text then you can view my playlist on my channel and I'll put a link to that in the description section below and if you're doing anything with web development related and you can watch my older sublime text setup video and I go over some additional packages that are good for you know linting HTML CSS JavaScript and things like that now I also have a video on how to set up the s UBL command line command in order to open files and folders and sublime text from your command line and I find that extremely useful and you can find those in the playlists that I just mentioned so I hope that people found this useful one of the most popular questions on the channel is you know what editor I'm using and how I set it up to run Python code so I hope now every one gets their setup exactly how they like now I've also had a lot of questions of people asking me for my opinion on Adam which is another editor that is becoming popular now I do like Adam and some good things is that you know it's completely free it's made by the people of github and it has a lot of support I've also put together a video on setting up by Python development environment within Adam also so that if anyone is interested in using that editor then they can see how that's done and I'll put a link to that in the description section below as well now if anyone is wondering if I would recommend sublime text or Adam and I would really just say that it depends now I think Adam is more user-friendly if you're just getting started out now if you don't want to purchase sublime text and I would say that Adam is a good option but I've been using sublime text for so long now that I'm more used to it and find myself always going back to it so you know really the choice is just up to you okay so I think that about does it if anyone has any questions about what we covered in this video then feel free to ask in the comment section below and I'll do my best to answer those now if you enjoy these tutorials and would like to support them then there's several ways you can do that now the easiest way is to simply like the video and give it a thumbs up and also it's a huge help to share these videos with anyone who you think would find them useful and if you have the means and you can contribute through patreon and there's a link to that page in the description section below be sure to subscribe for future videos and thank you all for watching
Info
Channel: Corey Schafer
Views: 829,285
Rating: 4.9095268 out of 5
Keywords: Sublime Text, Sublime, SublimeText, Python, Python Sublime Text, Sublime Text Sublime, Package Control, Install, Development Environment, Dev Environment, Development, Anaconda, Programming Tutorials, Python Tutorial, Software Engineering, How to, How-to, Sublime Text Tutorial, Predawn, Material Theme
Id: xFciV6Ew5r4
Channel Id: undefined
Length: 26min 2sec (1562 seconds)
Published: Wed Feb 15 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.