Installing Python, Pip, and Jupyter Notebooks
- [Instructor] This is the part of the course where knowing your way around a computer is going to come in handy. Every computer operating system and file configuration is different. These things get updated and changed all the time, and while I hope your installation goes flawlessly, I can't guarantee it. To assist with any road bumps, I've created a Troubleshooting document in the Exercise Files that goes over everything step by step, and also includes a link to the Troubleshooting Wiki on GitHub. If you go through all of these and you still think that your problem is unique, hit me up in the Q&A section on the Course page. I may add your problem and the solution to the Troubleshooting Wiki to help people out in the future. Can't find the Exercise Files? They're on the Overview tab of the Course page or you can get to them from the GitHub link. If you don't know how to use GitHub tools, on the GitHub page, you can just go to Code and then Download ZIP. Make sure that you unzip the files before you try to use them. Also, save them to a place that's easy to locate where you know where they are. This can be your Documents, or Desktop, or somewhere easily reachable. Again, there's that Troubleshooting document that you're going to want to check if you run into problems. Okay, so let's get started with installation. First, we need to install Python. Go to python.org/downloads. You should see a big yellow button here. The website automatically detects your operating system, and it should be showing you the latest version for your operating system here. Download it and then go through the installer. So this is very important. For Windows users, click Customize Installation, go to Next, and click Add Python to environment variables. Very important that you check this box. If you don't check Add Python to environment variables, you'll have to consult the Troubleshooting Guide later on. Finish the installation and you're set. If you're on a Mac, you may get a popup after installation. Just close it. Next, you need to find your computer's terminal. This is where programmers enter commands. Hopefully, you've used it before or at least seen it around. On Windows, you're going to go to Start and click on the Command Prompt, or you can search for CMD and it will show up there. On Macs, go to Applications, Utilities, and Terminal. On Linux, it varies by distribution, so just look that one up. It should be easy to find because you tend to need the terminal a lot in Linux. Now test your Python installation by typing python and hit Enter. On a Mac, you may need to type python3 instead of just python. This is to differentiate between Python Versions 2.0 and 3.0, which often both come on Macs. Hit Enter, and this should open up the Python command prompt indicated by the three greater than signs right there. So this is the Python command prompt where you can enter Python code. Make sure that the version number printed here matches the version that you downloaded from the website. Again, if you're on a Mac and you see a version that starts with 2 instead of 3, you may need to type python3 to get the correct version. We can test our Python environment by, say, typing 1 + 1. Hit Enter, and great, we get 2. Looks like everything's in working order. Now, we'll need to exit the Python command prompt to install the rest of what we need. We can do this by typing Control + D. Yes, even for Macs, it's Control + D and not Command + D. Or on Windows, type Control + Z, and hit Enter. On all operating systems, you can type quit, then open parenthesis, close parenthesis, and hit Enter. Okay, so now that we're back to our operating systems terminal, we can start the rest of the installation. Okay, so now, we're back to our operating systems terminal. We're not in the Python terminal anymore. Make sure you've definitely exited the Python command prompt and you don't see the three greater than signs. And now we're going to use a tool that should have been installed with Python, and that's called pip, the package installer for Python. So this is Python's package management system, and you can use it by typing pip. If I hit Enter right away, you can see a list of commands associated with it. Now, we're going to use pip to install a program called JupyterLab. JupyterLab is a piece of software that lets us view and edit Python Notebook files, the files with the .ipynb extension that make up most of the Exercise Files for this course. So I'm going to type pip install jupyterlab, that's Jupyter with a Y, and hit Enter. So wait a little bit, and it should be installed. Next, you'll need to use the command line to navigate to where your Exercise Files are stored. The command that you're going to want to type is cd, which stands for change directory. Then you'll need to enter the file path for where you stored your Exercise Files. I'm going to show you another way to do this later on, but one really easy way is to open up File Explorer or Finder and just copy the folder and paste it into your terminal. Then, hit Enter. Now we've navigated to the correct directory. Now that you're in the directory where your Exercise Files are, you're going to type jupyter lab, space lab, and this is going to start the Jupyter Notebook server on your computer using the Jupyter software that we just installed. This should cause a browser window to pop up so that we can see all of the Exercise Files in there. Now, Jupyter isn't the only software that can display these files. Visual Studio Code is an excellent development environment that can be used to run Python Notebook files, as well as develop larger pieces of Python code. We'll be using Visual Studio Code at several points during this course, so I recommend that you download it from code.visualstudio.com, and know that if you run into issues with your JupyterLab installation, you can use this as well to work with Notebook files. So back to JupyterLab. I'm going to open up one of these Notebook files here. You can do that just by clicking on the file in the left, and then you can run these cells. Each cell is just a little bit of Python code that you can run independently. So play around with these a little if you want. We're going to be using them very heavily shortly in this course, but next, we're going back to the command line for the next video.
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。