{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Goal #1: practice navigating the computer from a command prompt\n", "===============================================================\n", "\n", "We will be running files containing Python code (Python \"scripts\") from the command prompt. You'll need to be able to navigate to those scripts using the command prompt so you can run them. In this section, we'll practice using these navigation commands.\n", "\n", "The filesystem on your computer is like a tree made up of folders (also called \"directories\") and files. The filesystem has a root directory called `C:\\`, and most everything on your computer lives in subdirectories of this root directory (though you may also have separate *drives*, like `D:\\` and `E:\\`).\n", "\n", "We often navigate the filesystem graphically by clicking on graphical folders. We can do the exact same navigation from the command line.\n", "\n", "There are two commands that we'll be using at a command prompt to navigate the filesystem on your computer:\n", "\n", " dir\n", " cd\n", "\n", "``dir`` lists the contents of a directory.\n", "``cd`` moves you into a new directory (it stands for \"change directory\").\n", "\n", "Let's practice using these commands.\n", "\n", "Open a command prompt:\n", "----------------------\n", "\n", "*On Windows Vista or Windows 7:* click on the Start menu (the Windows logo in the lower left of the screen), type ``cmd`` into the Search field directly above the Start menu button, and click on \"cmd\" in the search results above the Search field.\n", "\n", "*On Windows XP:* click on the Start menu (the Windows logo in the lower left of the screen), click on ``Run...``, type ``cmd`` into the text box, and hit ``Enter``.\n", "\n", "Practice using dir and cd\n", "-------------------------\n", "\n", "Type each of these commands and hit ``Enter``:\n", "\n", " dir\n", "\n", "This lists all the files in your home directory.\n", "\n", " cd C:\\\n", "\n", "This will change you into the ``C:\\`` directory.\n", "\n", " dir\n", "\n", "This lists the contents of the ``C:\\`` directory.\n", "\n", " cd Users\n", "\n", "This will change you into the Users subdirectory of the ``C:\\`` directory.\n", "\n", " dir\n", "\n", "You should see the names of all the files and directories in ``C:\\Users``.\n", "\n", " cd ..\n", "\n", "``..`` means \"parent directory\", so this command moved you up to the parent directory. You were in ``C:\\Users``, so now you are in ``C:\\``, the root directory.\n", "\n", " dir\n", "\n", "This lists the contents of the root directory, confirming where you are.\n", "\n", "Tips\n", "----\n", "\n", "* You can use Tab to auto-complete directory and file names. So from inside the root directory, if you type ``cd Use`` and hit ``Tab``, the command prompt will auto-complete the directory name, and you can then hit enter to change into the ``C:\\Users`` directory.\n", "\n", "* The command prompt maintains a command history. You can use the up arrow to cycle through old commands.\n", "\n", "* Note that the text that makes up the command prompt changes as you move around directories. The command prompt will always give the full directory path to your current directory.\n", "\n", "Check your understanding\n", "------------------------\n", "\n", "Answer these questions. Experiment at the command line if you need to! If you aren't sure about an answer, ask a helper.\n", "\n", "* What directory are you in after starting a new command line prompt?\n", "* After starting a new command line prompt, how would you get to the root directory?\n", "* How do you check what files and directories are in your current working directory?\n", "* If you are in directory ``C:\\Users``, and you want to get to ``C:\\Users\\jesstess\\projects``, how would you do that?\n", "* What are 2 ways to avoid typing out a full navigation command? (hint: one requires that you've run the command before)\n", "* What is the difference between a command prompt and a Python prompt?\n", "\n", "Success!\n", "--------\n", "\n", "You've practiced using ``dir`` and ``cd`` to navigate your computer's filesystem from the command prompt.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Goal #2: Install software\n", "=========================" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Copy the files\n", "--------------\n", "\n", "Insert the CD or USB drive provided by an instructor. Using Windows Explorer (start it by pressing Windows key + \"E\"), drag the \"workshop\" folder onto the Desktop of your own computer to make your own copy of the class materials. Then you can remove the CD or USB drive and pass it along. If you can't use a CD or USB drive, download [this file](https://github.com/catherinedevlin/mpwfw_exercises/archive/master.zip) and have an instructor help you prepare it.\n", "\n", "Install Anaconda Python\n", "-----------------------\n", "\n", "The [Python](python.org) programming language is *\"open-source\"* - no single person or company owns it, or can own it - it's for everyone to use. Some companies wrap it up together with useful related programs. We'll use one such packaging called [Anaconda](https://store.continuum.io/cshop/anaconda/), published free of charge by [Continuum Analytics](https://store.continuum.io), because that's the most reliable way to get everything we need installed.\n", "\n", "Double-click the \"workshop\" folder you just copied to enter it, then enter the \"windows\" folder.\n", "\n", "*If your computer is 64-bit*: Double-click \"Anaconda-1.7.0-Windows-x86_64.exe\" and accept all the defaults to install Python.\n", "\n", "*If your computer is 32-bit*: Double-click \"Anaconda-1.7.0-Windows-x86.exe\" and accept all the defaults to install Python.\n", "\n", "*Ugh, you're already confusing me!*: I know, that's not a beginner-level question! So try double-clicking \"Anaconda-1.7.0-Windows-x86_64.exe\". If that works, your computer is 64-bit, so go ahead and follow the 64-bit directions. If you get an error message saying something like \"not supported by this processor\", your computer is 32-bit, so follow those directions instead.\n", "\n", "Install Notepad++\n", "-----------------\n", "\n", "Next, back in the \"Desktop\\workshop\\windows\\install\" folder in Windows Explorer, double-click the `npp.6.4.5.Installer.exe` file. This will install Notepad++, a \"text editor\" good for writing programs with. (Your computer came with other \"text editors\" like Notepad and WordPad, but those editors will mess up your programs if you try to write with them.) Again, accept all the defaults that the installer suggests.\n", "\n", "Like Python, this program is free and open-source." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Goal #3: practice starting and exiting Python\n", "=============================================\n", "\n", "We'll do some learning and practicing at a Python prompt (this is \"interactive\" because you are typing the code and hitting enter to run it yourself, instead of running it from a file). So let's practice starting and exiting Python:\n", "\n", "1. Open a command prompt:\n", "\n", "*On Windows Vista or Windows 7:* click on the Start menu (the Windows logo in the lower left of the screen), type ``cmd`` into the Search field directly above the Start menu button, and click on ``cmd`` in the search results above the Search field.\n", "\n", "*On Windows XP:* click on the Start menu (the Windows logo in the lower left of the screen), click on ``Run...``, type ``cmd`` into the text box, and hit enter.\n", "\n", "2. To start Python, type\n", "\n", " python\n", "\n", "at the command prompt and hit ``Enter``. You should see something like\n", "\n", " Python 2.7.1 (r271:86832, ...) on win32\n", " Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n", " >>>\n", "\n", "The ``>>>`` indicates that you are at a Python prompt. If it does, hooray! You can skip down to \"Exiting Python\".\n", "\n", "If Python doesn't start\n", "-----------------------\n", "\n", "Instead of the Python prompt, do you see a message like\n", "\n", " 'python' is not recognized as an internal or external command,\n", " operable program or batch file.\n", "\n", "Darn! The installation script from Goal #2 was supposed to add Python to your PATH, but that script doesn't work on every computer. (It's not your fault!) That means we have to add Python to the PATH by hand. \n", "\n", "*\"What's the PATH\"? It's a list of all the directories your computer should look in when you type a command like 'python'.*\n", "\n", "So here's what we do. Feel free to ask for help if you're having trouble.\n", "\n", "* Close your command prompt window\n", "\n", "* Get to System Properties\n", "\n", "Open up \"My Computer\" by clicking on the Start menu or the Windows logo in the lower-left hand corner, and navigate to \"My Computer\" (for Windows XP) or \"Computer\" (For Vista and Windows 7).\n", "\n", "Right-click on the empty space in the window, and choose Properties.\n", "\n", "*If you're using XP*, a window labeled \"System Properties\" will pop up. Click the \"Advanced\" tab.\n", "\n", "*If you're not using XP*, a window labeled \"View basic information about your computer\" will appear. \n", " - In this window, click \"Advanced system settings\". \n", " - A window with the title \"System Properties\" will appear.\n", "\n", "* Edit the Path\n", "\n", " - Within System Properties, make sure you are in the tab labeled \"Advanced\".\n", " - Click the button labeled \"Environment Variables\".\n", " - A window labeled \"Environment Variables\" will appear.\n", " - In this window, the screen is split between \"User variables\" and \"System variables\". Within \"System variables\", scroll down and find the one labeled Path. Click the \"Edit...\" button.\n", " - A window with the \"Variable name\" and the \"Variable value\" should appear. The \"Variable value\" will already have some text in it; click in the box to unhighlight it (we don't want to accidentally delete that text).\n", " - In the \"Variable value\" box, scroll to the end. Add the following text, and hit OK. Make sure to include the semicolon at the start!\n", "\n", " ;c:\\python27\\;c:\\python27\\scripts\n", "\n", " - Hit \"OK\" to close out the system properties window.\n", "\n", "To test your new PATH, open up a *new* command prompt; it needs to be a new command prompt because the changes you just made didn't take affect in prompts that were already open. Now go back to the beginning of Goal #3 and start again. This time you should be able to skip this middle section!\n", "\n", "Exiting Python\n", "--------------\n", "\n", "Exit the Python prompt by typing\n", "\n", " exit()\n", "\n", "and hitting enter. Now you're back at the Windows command prompt (C:\\).\n", "\n", "Check your understanding\n", "------------------------\n", "\n", "What is the difference between a command prompt and a Python prompt? If you're not sure, ask a helper.\n", "\n", "Success!\n", "--------\n", "\n", "Practice these steps until you feel comfortable navigating to a command prompt, starting Python, and exiting Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Goal #4: Configure your text editor\n", "===================================\n", "\n", "Next you need to get Notepad++, the text editor that you just installed, ready to work with Python. (Notepad++ is different from the Notepad that came with Windows - plain old Notepad will make a mess of your programs if you try to use it.) \n", "\n", "First, start Notepad++:\n", "\n", "* In Windows Vista or Windows 7, click on the Start menu, type Notepad++ in the Search Field, and hit enter.\n", "* In Windows XP, click on the Start menu, navigate to All Programs, and then navigate to Notepad++.\n", "\n", "Now, follow these steps to tell the editor to use spaces instead of tab marks when you indent:\n", "\n", "* Within Notepad++, Click Settings -> Preferences\n", "* Find the tab labeled \"Language Menu/Tab Settings\"\n", "* Find the box labeled \"Replace by space\", and make sure it is checked\n", "* Click Close.\n", "\n", "That's it! Now, you can hit tab to indent your code, and that indentation will actually be made of spaces. This change will help you use spaces consistently, so that Python doesn't get confused about whitespace.\n", "\n", "Success!\n", "--------\n", "\n", "If you'd rather use a different editor for text, check with an instructor before moving on to make sure it will work for the weekend.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Goal #5: practice running Python code from a file\n", "=================================================\n", "\n", "Interactive Python programming at a Python prompt is great for short pieces of code and for testing ideas. For longer code, it can be easier to save the code in a file, and execute the contents of that file (aka a Python script). In this section, we'll practice running Python scripts.\n", "\n", "Start your text editor\n", "----------------------\n", "\n", "- Launch the Notepad++ text editor. See Goal #4 for the steps to do this.\n", "- Start a new, blank text file.\n", "\n", "Write and save a short Python script\n", "------------------------------------\n", "\n", "Add the following line to your new text file:\n", "\n", " print \"Hello World!\"\n", "\n", "Save the script as hello.py in your Desktop directory. The ``.py`` extension indicates that this file contains Python code.\n", "\n", "Run the script\n", "--------------\n", "\n", "* Start a new command prompt. See the terminal navigation on Windows instructions for the steps to do this. Recall that a terminal prompt will look like ``C:\\`` and a Python prompt will look like ``>>>``. Make sure you are at a terminal prompt and not a Python prompt; if you are at a Python prompt, you can type ``exit()`` on a line by itself and then hit ``Enter`` to exit Python and return to a terminal prompt.\n", "\n", "* Navigate to your Desktop directory from a command prompt, using the ``dir`` and ``cd`` commands. See the terminal navigation on Windows instructions for a refresher on using these commands. Don't hesitate to get help from a staff member on this step if you need it -- it's a new way of navigating your computer, so it may be unintuitive at first!\n", "\n", "* Once you are in your Desktop directory, you'll see hello.py in the output of dir.\n", "\n", "* Type\n", "\n", " python hello.py\n", "\n", "and hit ``Enter``. Doing this will cause Python to execute the contents of that script -- it should print \"Hello World!\" to the screen. What you've done here is run the Python application with an argument -- the name of a file, in this case \"hello.py\". Python knows that when you give it a file name as an argument, it should execute the contents of the provided file. You get the same result as if you typed\n", "\n", " print \"Hello World!\"\n", "\n", "at a Python prompt and hit ``Enter``.\n", "\n", "Success\n", "-------\n", "\n", "You created and ran your first Python script!\n", "\n", "* When you run the python command by itself, you start a Python prompt. You can execute Python code interactively at that prompt.\n", "* When you run the python command with a file name as an argument, Python executes the Python code in that file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Goal #6: Practice using IPython Notebook\n", "========================================\n", "\n", "You'll spend most of this workshop using a Python tool called the *IPython Notebook*.\n", "This lets you run IPython cells, which are like the interactive Python prompt you tried out\n", "in Goal #3, right within your browser.\n", "\n", "Open a command window (see Goal #1) and use `cd` to navigate into the `workshop` directory:\n", "\n", " cd Desktop\n", " cd workshop\n", "\n", "Type\n", "\n", " ipython notebook\n", "\n", " and hit `Enter`.\n", "\n", "Your browser should come up with a page called \"IP[y]: Notebook\". That's your IPython Dashboard; it has a list of notebooks. Click \"notebook_practice\" and follow the instructions on the notebook that it brings up.\n", "\n", "Goal #7: Tutorial\n", "=================\n", "\n", "Go back to the IPython Dashboard page in your browser, and click the \"day1.1\" notebook. Follow along through that tutorial. Remember to ask lots of questions, to the instructors and to the other students - we're all here to help each other!\n", "\n", "After \"day1.1\", you'll go through \"day1.2\" and then part of \"exercises\". We'll leave the rest for tomorrow!" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }