Installation in MacOS & Linux;
So, the first thing that we need to do to get into programming in Python is installing it. So, let's go ahead and discuss about the three different ways that you're going to be installing it. First, we're going to cover Mac because that's what i'm using and so it's easiest to show you how to do it. So, what you're going to do is open up terminal which I've moved into that folder and put right here.
Now, if you haven't installed Home brew, what you're going to do is runa Ruby command that's going to download and set it up. So, basically what Home brew is, is a package manager that you can use to install a lot of packages. So,if you're used to Linux basically on Linux if you want to install a package you don't need to go all around the internet and search for packages on websites and then download from shady sources and get viruses, that's just a bad construct of computer operating systems, but unfortunately that's how Windows works and so i'm going to show you guys the right way to install in Windows as well. Using Linux or OS 10 you're going to be installing through terminal. So, first setup Home brew, this is how you do it, come to brew.sh and it's going to give you this line of code here. You just paste this in terminal, run it, it's going to install brew.
Once you've got brew installed what you're going to do is run"brew install python" Now that's how easy it is. OS 10 does ship with a version of Python but the the version included in OS 10 is 2.7 series and I think it's actually an old really something that's like to 2.7.5 or something like that so it's pretty old. At least I think it was that.
We can actually run "--python version" here, so okay so the version that OS 10 El Capitรกn ships with is 2.7.10. When you run brew install Python it's going to install python 3, that's the command that we're going to have to be using because there's already a Python version installed, so we're going to be using Python 3 and you can check the version we've got 3.5.1 that's the version that home brew is going to install for you. Now similarly if you're on Linux what you would do there's a few different ways because there's a few different package managers. So if you're on Arch Linux I don't think you're gonna need help setting it up, and actually a lot of Linux distributions have Python/Python 3 pre-installed, so you can just run "python --version" and "python3 --version" and see what version you have installed,you might need to upgrade, it it might be fine. If you have 3.4 you can follow along with this course I don't think there's that many differences between the two versions and there's definitely not code-breaking differences, so that shouldn't be a problem. However, if you do notice that you're having a problem you could upgrade the version of Python either through the repository or otherwise.
If you're on Ubuntu you're gonna be using the apt-get command, so you'd run "sudo apt-get install python 3" That's going to install Python 3 for you. If you're on Fedora I believe it used to be yum, I think it's dnf now. Yeah, so let's just review exactly what commands you're going to be using, I think it's like dnf install. So, you can still use yum I guess, okay so you can use yum to install. So, what you're gonna do is we're gonna run "sudo yum install" and then I believe the package is just called python 3, Python 4 is going to be pretty amazing but right now we're using Python 3. So,there we go. Now if you're on Arch and I said I don't think you need any help getting it setup but just for you know if you are new to Arch you'd run"sudo pacman -S python 3" but again python 3 should be pre-installed, so you shouldn't even need to do any of this but if you do that's gonna do it.
Now on Windows you do need to go download a file from the internet and run it,the difference between what I said before what I'm saying now is this is not a shady location. So, what you're going to do is go to python.org, go to the download sections, and if you just hover over this it's actually going to show you a drop-down and you can choose what platform you're on. So you would choose windows and they actually have a 3.6 which we're not going to we're not going to be using because this is in alpha. So, click latest python 3 release python 3.5.1, it's going to take you to this page and basically give you a change log and what not. If you go down here make sure you get the version that's compatible with your system. If you have a computer that is not obsolete it should be running a 64-bit operating system which means it has a 64-bit processor. S,o you would download this one right here, Windows x86 64 executable and what that's going to download is an .exe file which you can use to install the program.
If you're running a 32-bit system you're going to download this one just the x86, and yeah just install it. Now, there is one note on the installation, when you run the installation there's going to be a certain step where you have some check boxes and one of them is going to say add python to the path variable, make sure that's checked because if it's not checked if you try to run Python in the command line you won't be able to because it won't know where to find this mysterious Python command. So, by checking that box basically it tells windows where the Python binary file is located, so you want to make sure Windows is aware of where that file is.
And that's all there is to installing it. To confirm that you've got it installed open up a command prompt to terminal and just type Python3 and it should drop you down into the interpreter, which we're going to be discussing in the next Post.
Installation in Window 10;
Alright guys, so, we've already learned about installing and using Python within Mac OS and Linux. Those two operating systems actually have a very similar process that's because they're both derived from the UNIX operating system, where Windows is not. So, Windows is a little bit different, so I'm going to walk you guys through this right now. You need to go to python.org, once you get to python.org you need to hover over downloads here, and then find Windows here. It should also be defaulted to Windows if you're on Windows. So, we're going to be choosing which version we're going to be using and we are always going to be using Python 3 not 2, so ignore Python 2. Click Python 3.6.1 and it's going to download the installer for you. Now, when this is done downloading we can install it. So just launch the program, and let me just uninstall this first so that I can reinstall it. While this is uninstalling we're going to be talking about the environment variables and why you need them, and when I installed Python on Windows a while back there was a problem with the path, or maybe not the path but specifically the Python installer package which we're going to be discussing. And if you guys do have the problem that I had it's going to be terrible, but there's an easy workaround for it. Alright, so, let's close that and then run the Python 3.6 installer. Now there's one very important thing that we need to do and that is you need to check add Python 3.6 to path, and then click install now. Now while that's doing that, I'm going to search for control panel here, and in the control panel let's go into system. If you don't see this view right-click up here and select small icons. This should work on Windows 7 8, or 10, and everybody should be on one of those operating systems anyway because, Vista might not be end of life yet. Vista it was either April or May that that was happening and it's April now. So, anyway, if you're on Windows 7, 8, or 10 go to system and on the left-hand side click advanced system settings. It's going to pop this up right here. Specifically, if you are not on the Advanced tab to begin with, if you're someone over here, go to the Advanced tab, and now here at the bottom you're going to see an environment variables button. Click that and it's going to bring up the environment variables configuration screen. Now the specific one that we're interested in is the path variable. These are system variables and these are user variables, I'm going to double click on this path variable and as you can see we've got python 3.6 3.2 added to the path which means every time I run a program that resides in one of these paths, Windows is going to know where to look for it because it's going to check all these paths first, and then all these paths in that one. And then if it doesn't find it then it's going to say, okay, well, I don't really know what you're looking for, and that's why we add paths to the path variable. So, that has been added, if I open up a command prompt here you will see that if I run Python it's going to successfully find it and run the program. Now that is because I have it installed to that path. Up here you can see users, my user, app data, local, etc., and as you can see right here that is the path that was added. So, every time I run Python this is one of the first paths it checks, and it goes well, do I have a Python.exe file, and it does. Now you can also run all of the programs from the scripts directory including pip, and so that's what we're going to talk about right now. Let me exit out of here. So, pip basically for example if you wanted to build a web scraper or a web crawler and if you just wanted to have a program that would download certain pages, what you would have to do is build scraper. And in PHP, for example, you have access to curl, it's shipped with curl. There is no default requests library for Python, so you'll have to install one. And usually you are going to be using some type of framework or library within Python just because it doesn't make sense to continue rewriting things that other people already have. So, you're going to be doing a lot of this, so I recommend getting used to it. We're going to go ahead and install a package that we're going to be using for web scraping and that is called requests. So what you need to do is type pip install, and then the name of the package you want to install. Now this is the problem I was getting before so I guess a re installation did not fix the problem, and I have no idea what the problem is I've been reading this stack overflow thread and so far I haven't discovered what the problem is, but there are a few workarounds. So number one probably the one we're going to go with is since you can run Python from the command line because that's been added to the path you can actually work around this by typing python -m pip install requests, and I've already got it installed so it's just going to say requirement already satisfied, but it should install for you guys. Anytime you see me in this course type pip install anything, all you Windows guys remember use python -m pip install and then whatever you're going to install. So that is how you install things with pip, and now once we've got this installed if I were to jump back into Python you can just import the library that you just created, and now you have access to that class. And that is how to get set up with this stuff on Windows. I hope you guys enjoy this course, I'm definitely going to.
So, the first thing that we need to do to get into programming in Python is installing it. So, let's go ahead and discuss about the three different ways that you're going to be installing it. First, we're going to cover Mac because that's what i'm using and so it's easiest to show you how to do it. So, what you're going to do is open up terminal which I've moved into that folder and put right here.
Now, if you haven't installed Home brew, what you're going to do is runa Ruby command that's going to download and set it up. So, basically what Home brew is, is a package manager that you can use to install a lot of packages. So,if you're used to Linux basically on Linux if you want to install a package you don't need to go all around the internet and search for packages on websites and then download from shady sources and get viruses, that's just a bad construct of computer operating systems, but unfortunately that's how Windows works and so i'm going to show you guys the right way to install in Windows as well. Using Linux or OS 10 you're going to be installing through terminal. So, first setup Home brew, this is how you do it, come to brew.sh and it's going to give you this line of code here. You just paste this in terminal, run it, it's going to install brew.
Once you've got brew installed what you're going to do is run"brew install python" Now that's how easy it is. OS 10 does ship with a version of Python but the the version included in OS 10 is 2.7 series and I think it's actually an old really something that's like to 2.7.5 or something like that so it's pretty old. At least I think it was that.
We can actually run "--python version" here, so okay so the version that OS 10 El Capitรกn ships with is 2.7.10. When you run brew install Python it's going to install python 3, that's the command that we're going to have to be using because there's already a Python version installed, so we're going to be using Python 3 and you can check the version we've got 3.5.1 that's the version that home brew is going to install for you. Now similarly if you're on Linux what you would do there's a few different ways because there's a few different package managers. So if you're on Arch Linux I don't think you're gonna need help setting it up, and actually a lot of Linux distributions have Python/Python 3 pre-installed, so you can just run "python --version" and "python3 --version" and see what version you have installed,you might need to upgrade, it it might be fine. If you have 3.4 you can follow along with this course I don't think there's that many differences between the two versions and there's definitely not code-breaking differences, so that shouldn't be a problem. However, if you do notice that you're having a problem you could upgrade the version of Python either through the repository or otherwise.
If you're on Ubuntu you're gonna be using the apt-get command, so you'd run "sudo apt-get install python 3" That's going to install Python 3 for you. If you're on Fedora I believe it used to be yum, I think it's dnf now. Yeah, so let's just review exactly what commands you're going to be using, I think it's like dnf install. So, you can still use yum I guess, okay so you can use yum to install. So, what you're gonna do is we're gonna run "sudo yum install" and then I believe the package is just called python 3, Python 4 is going to be pretty amazing but right now we're using Python 3. So,there we go. Now if you're on Arch and I said I don't think you need any help getting it setup but just for you know if you are new to Arch you'd run"sudo pacman -S python 3" but again python 3 should be pre-installed, so you shouldn't even need to do any of this but if you do that's gonna do it.
Now on Windows you do need to go download a file from the internet and run it,the difference between what I said before what I'm saying now is this is not a shady location. So, what you're going to do is go to python.org, go to the download sections, and if you just hover over this it's actually going to show you a drop-down and you can choose what platform you're on. So you would choose windows and they actually have a 3.6 which we're not going to we're not going to be using because this is in alpha. So, click latest python 3 release python 3.5.1, it's going to take you to this page and basically give you a change log and what not. If you go down here make sure you get the version that's compatible with your system. If you have a computer that is not obsolete it should be running a 64-bit operating system which means it has a 64-bit processor. S,o you would download this one right here, Windows x86 64 executable and what that's going to download is an .exe file which you can use to install the program.
If you're running a 32-bit system you're going to download this one just the x86, and yeah just install it. Now, there is one note on the installation, when you run the installation there's going to be a certain step where you have some check boxes and one of them is going to say add python to the path variable, make sure that's checked because if it's not checked if you try to run Python in the command line you won't be able to because it won't know where to find this mysterious Python command. So, by checking that box basically it tells windows where the Python binary file is located, so you want to make sure Windows is aware of where that file is.
And that's all there is to installing it. To confirm that you've got it installed open up a command prompt to terminal and just type Python3 and it should drop you down into the interpreter, which we're going to be discussing in the next Post.
Installation in Window 10;
Alright guys, so, we've already learned about installing and using Python within Mac OS and Linux. Those two operating systems actually have a very similar process that's because they're both derived from the UNIX operating system, where Windows is not. So, Windows is a little bit different, so I'm going to walk you guys through this right now. You need to go to python.org, once you get to python.org you need to hover over downloads here, and then find Windows here. It should also be defaulted to Windows if you're on Windows. So, we're going to be choosing which version we're going to be using and we are always going to be using Python 3 not 2, so ignore Python 2. Click Python 3.6.1 and it's going to download the installer for you. Now, when this is done downloading we can install it. So just launch the program, and let me just uninstall this first so that I can reinstall it. While this is uninstalling we're going to be talking about the environment variables and why you need them, and when I installed Python on Windows a while back there was a problem with the path, or maybe not the path but specifically the Python installer package which we're going to be discussing. And if you guys do have the problem that I had it's going to be terrible, but there's an easy workaround for it. Alright, so, let's close that and then run the Python 3.6 installer. Now there's one very important thing that we need to do and that is you need to check add Python 3.6 to path, and then click install now. Now while that's doing that, I'm going to search for control panel here, and in the control panel let's go into system. If you don't see this view right-click up here and select small icons. This should work on Windows 7 8, or 10, and everybody should be on one of those operating systems anyway because, Vista might not be end of life yet. Vista it was either April or May that that was happening and it's April now. So, anyway, if you're on Windows 7, 8, or 10 go to system and on the left-hand side click advanced system settings. It's going to pop this up right here. Specifically, if you are not on the Advanced tab to begin with, if you're someone over here, go to the Advanced tab, and now here at the bottom you're going to see an environment variables button. Click that and it's going to bring up the environment variables configuration screen. Now the specific one that we're interested in is the path variable. These are system variables and these are user variables, I'm going to double click on this path variable and as you can see we've got python 3.6 3.2 added to the path which means every time I run a program that resides in one of these paths, Windows is going to know where to look for it because it's going to check all these paths first, and then all these paths in that one. And then if it doesn't find it then it's going to say, okay, well, I don't really know what you're looking for, and that's why we add paths to the path variable. So, that has been added, if I open up a command prompt here you will see that if I run Python it's going to successfully find it and run the program. Now that is because I have it installed to that path. Up here you can see users, my user, app data, local, etc., and as you can see right here that is the path that was added. So, every time I run Python this is one of the first paths it checks, and it goes well, do I have a Python.exe file, and it does. Now you can also run all of the programs from the scripts directory including pip, and so that's what we're going to talk about right now. Let me exit out of here. So, pip basically for example if you wanted to build a web scraper or a web crawler and if you just wanted to have a program that would download certain pages, what you would have to do is build scraper. And in PHP, for example, you have access to curl, it's shipped with curl. There is no default requests library for Python, so you'll have to install one. And usually you are going to be using some type of framework or library within Python just because it doesn't make sense to continue rewriting things that other people already have. So, you're going to be doing a lot of this, so I recommend getting used to it. We're going to go ahead and install a package that we're going to be using for web scraping and that is called requests. So what you need to do is type pip install, and then the name of the package you want to install. Now this is the problem I was getting before so I guess a re installation did not fix the problem, and I have no idea what the problem is I've been reading this stack overflow thread and so far I haven't discovered what the problem is, but there are a few workarounds. So number one probably the one we're going to go with is since you can run Python from the command line because that's been added to the path you can actually work around this by typing python -m pip install requests, and I've already got it installed so it's just going to say requirement already satisfied, but it should install for you guys. Anytime you see me in this course type pip install anything, all you Windows guys remember use python -m pip install and then whatever you're going to install. So that is how you install things with pip, and now once we've got this installed if I were to jump back into Python you can just import the library that you just created, and now you have access to that class. And that is how to get set up with this stuff on Windows. I hope you guys enjoy this course, I'm definitely going to.
gg
ReplyDelete