{ "metadata": { "name": "programming_environment_windows" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Programming Environment: Windows\n", "===\n", "This section will show you how to run your first Python program on a Windows computer." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Previous: Programming Environment](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/programming_environment.ipynb) | \n", "[Home](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/index.ipynb) | \n", "[Next: Hello World](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/hello_world.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Contents\n", "===\n", "- [Python on Windows](#python_on_windows)\n", "- [Installing Python](#installing_python)\n", " - [Installing Python 3](#installing_python_3)\n", " - [Installing Python 2](#installing_python_2)\n", "- [Installing Geany](#installing_geany)\n", " - [Telling Geany how to find Python](#geany_python)\n", " - [Python 3](#geany_python_3)\n", " - [Python 2](#geany_python_2)\n", " - [Troubleshooting](#geany_troubleshooting)\n", "- [Running Linux on your Windows computer](#linux_on_windows)\n", " - [Running Linux inside your Windows system](#linux_vm)\n", " - [Running Linux beside your Windows system](#dual_boot)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Python on Windows\n", "===\n", "If you use Windows on your own computer, you can install Python and start writing your own programs pretty quickly. You shouldn't have too much trouble as you area learning, but at some point you might notice that some of the resources you'd like to use are written for Linux or Mac users. At that point you will have a number of options, and we will help you work through those issues when they come up." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Installing Python\n", "===\n", "Python is probably not installed on your system yet. To find out if it is installed, open a terminal and type the word `python`. If you haven't used a terminal before, go to your Start menu and start typing the word 'command'. You will see an icon for the Windows command console, a black icon. Click this, and type the word 'python'. You will probably get a message that Windows does not recognize 'python' as a command.\n", "\n", "If you do have Python installed, you can skip to the section on [installing Geany](#installing_geany)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Installing Python 3\n", "---\n", "Since you are starting out fresh, it's probably a good idea to just install the newest stable version of Python. Most people who still use Python 2 do so because they have to maintain large projects that were written for Python 2. Unless you know you will have to maintain an existing project you are probably better off learning Python 3 from the beginning.\n", "\n", "The main Python website has a section written just for [beginners who are trying to install Python](https://wiki.python.org/moin/BeginnersGuide/Download). If you get stuck, take a look at that page and see if anything seems to make sense for your particular system.\n", "\n", "Here is what has worked for me, for both Windows 7 and Windows 8:\n", "\n", "- Go to the [Download](https://wiki.python.org/moin/BeginnersGuide/Download) page on the official Python Beginner's Guide.\n", "- If you are running Windows 7 or 8, look for the line that says **If you're running Windows**.\n", " - Click on the \"Python 3.2.3 for Windows\" link.\n", " - This will download an installer, which will install Python 3.2 for you.\n", " - You should be fine accepting all of the default settings, unless you see a particular reason to change something.\n", "- If you are running Windows XP, look for the line that says, **If you're running Windows XP**.\n", " - Follow the links provided to install Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Testing your Python installation\n", "---\n", "Once Python has finished installing, you want to make sure it is working. There are several ways to do this.\n", "\n", "- Start Menu > Python (command line) OR Start Menu > Python > Python (command line)\n", " - This should open up a terminal window, with Python running.\n", " - Type `print(\"Hello Python world!\")`, and press Enter.\n", " - You should see your message displayed back to you in the terminal window.\n", "- Open a command window (Start Menu > type \"command\", and click the black terminal icon)\n", " - Type `C:\\Python32\\python`, and press Enter\n", " - You should see a Python prompt.\n", " - Type `print(\"Hello Python world!\")`, and press Enter.\n", " - You should see your message displayed back to you in the terminal window." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Installing Python 2\n", "---\n", "If you want to start out on Python 2, the instructions are almost identical to installing Python 3. Follow the instructions above, but when you get to the step for choosing an installer, look for the \"Python 2.7.3 for Windows\" link.\n", "\n", "When you try to open a terminal window and run Python, your path will probably be `C:\\Python27\\python`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[top](#)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Installing Geany\n", "===\n", "Geany is a simple text editor, which makes it easy to run Python programs. Output is displayed in a separate terminal window, which gets you used to working in terminals as well." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Go to Geany's [download page](http://www.geany.org/Download/Releases).\n", "- Download the full installer, which is described as *Full Installer including GTK 2.16*.\n", " - This is the current direct link to the installer for [Geany 1.23.1](http://download.geany.org/geany-1.23.1_setup.exe).\n", "- Write a [Hello World](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/hello_world.ipynb) program, and save it as 'hello.py'.\n", "- There are three ways you can run a program in Geany:\n", " - Build > Execute\n", " - Press F5\n", " - Click the icon with three gears on it\n", "- You would hope see a terminal window pop up, with your output in it, but you probably won't see this yet:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Hello Python world!\n", "\n", "\n", " ------------------\n", " (program exited with code: 0)\n", " Press return to continue" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You will probably see an error message, because Geany doesn't know where Python lives on your system. We will fix that in the next section." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Telling Geany how to find Python\n", "---\n", "You probably have to configure Geany to tell it how to find the version of Python that you just installed.\n", "\n", "Open Geany, and open a Python [Hello World](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/hello_world.ipynb) program. If you don't have one on your system, write one and save it as *hello.py*, and run the program. This makes sure that Geany is trying to run Python programs. When you have a running *hello.py* program, go to Build >> Set Build Commands.\n", "\n", "### Python 3\n", "\n", "Under 'Python commands', look for the 'Compile' line. Enter the following in the 'Command' box. Make sure you get the spaces right. You should have 'C:\\Python32\\python' followed by a space, and the rest of the command. If you have 'Python 32', with a space between *Python* and *32*, Geany will not be able to run your code. Also, make sure your capitalization matches what you see here exactly.\n", "\n", " C:\\Python32\\python -m py_compile \"%f\"\n", "\n", "Under 'Execute commands', look for the 'Execute' line. Enter the following in the 'Command' box, paying attention once again to the spaces.\n", "\n", " C:\\Python32\\python \"%f\"\n", "\n", "Test your setup by running *hello.py* again.\n", "\n", "### Python 2\n", "\n", "If you installed Python 2 instead of Python 3, the commands you want are probably:\n", "\n", " C:\\Python27\\python -m py_compile \"%f\"\n", "\n", "and\n", "\n", " C:\\Python27\\python \"%f\"\n", "\n", "### Troubleshooting\n", "\n", "If Geany still cannot run your *hello.py* program, check to see if your installation of Python is somewhere else.\n", "\n", "- Open Windows Explorer.\n", "- Search for 'python'.\n", "- Look for the path to your system's Python. It is probably something like `C:\\Python`*xxx*`\\python`.\n", " - If you find it, that is the path you want to use in the above settings." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[top](#)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running Linux on your Windows computer\n", "===\n", "If you have run into any difficulty configuring your Windows system to run Python, you may want to consider running Linux on your system. You can do this without affecting your Windows installation, if you are careful.\n", "\n", "The best ways to do this are:\n", "- After your machine is fully backed up, and you are capable of rebuilding it.\n", "- With a friend who knows their way around Windows and Linux.\n", "- With a Windows installation disc, so that if you mess anything up you can rebuild your Windows system.\n", "- With an older machine that you don't care too much about.\n", "\n", "Some bad ways to do this are:\n", "- With a bunch of family photos, music, and documents on your system that are not backed up.\n", "- With no ability to re-install your system if anything goes wrong.\n", "- On your parent's/ sibling's/ partner's computer.\n", "\n", "That said, you shouldn't be scared at all about Linux. Linux has gotten pretty user-friendly, and once you have it installed it will behave like most other modern operating systems." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running Linux inside your Windows system\n", "---\n", "You can install something like [VirtualBox](https://www.virtualbox.org/wiki/Downloads) or [VMWare](http://www.vmware.com/), and install Linux within your current Windows installation. To run Linux under this configuration, you would:\n", "\n", "- Start VirtualBox or VMWare.\n", "- Start your virtual Linux computer.\n", "- Use your computer as you would a Linux computer.\n", "- Shut down your Linux machine, and find yourself right back in Windows.\n", "\n", "In this scenario, you are letting Windows manage the Linux computer.\n", "\n", "*Specific instructions for this will be added shortly.*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running Linux beside your Windows system.\n", "---\n", "In this configuration, you load Linux as a separate operating system on your computer. To run Linux under this configuration, you would:\n", "\n", "- Turn your computer on, and be given a choice to either boot into Windows or boot into Linux.\n", "- Choose Linux.\n", "- Use your computer as a Linux machine.\n", "\n", "In this scenario, neither system is really aware of the other. Your computer only knows, when you turn it on, that there are two separate operating systems available to you.\n", "\n", "*Specific instructions for this will be added shortly.*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[top](#)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- - -\n", "[Previous: Programming Environment](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/programming_environment.ipynb) | \n", "[Home](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/index.ipynb) | \n", "[Next: Hello World](http://nbviewer.ipython.org/urls/raw.github.com/ehmatthes/intro_programming/master/notebooks/hello_world.ipynb)" ] } ], "metadata": {} } ] }