{ "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](#Telling-Geany-how-to-find-Python)\n", " - [Python 3](#Python-3)\n", " - [Python 2](#Python-2)\n", " - [Troubleshooting](#Troubleshooting)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Python on Windows\n", "===\n", "If you use Windows, you can install Python and start writing your own programs pretty quickly. You shouldn't have too much trouble as you're 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'll have a number of options, and we'll help you work through those issues when they come up." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Installing Python\n", "===\n", "Python is not usually installed by default on Windows systems. To find out if it's 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'll see an icon for the Windows command console. You can also hold the Shift button while right-clicking the mouse.\n", "\n", "Enter the word `python` in the terminal, and press Enter. You'll 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're installing Python yourself starting out fresh, it's 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 originally written for Python 2. Unless you know you'll have to maintain a large existing project, you're 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", "Go to the [Download](https://www.python.org/downloads/windows/) page on [python.org](http://python.org), and download an installer that's appropriate for your system. Look for a Python 3.4 installer. It's helpful to know whether you're running a 32-bit or 64-bit version of Windows; if you don't know, download a 32-bit installer. 32-bit installers will work on any system; 64-bit installers will only work on 64-bit systems." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Testing your Python installation\n", "---\n", "Once Python has finished installing, you'll want to make sure it's 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:\\Python34\\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": [ "[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.24](http://download.geany.org/geany-1.24_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", "- We should 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'll probably see an error message, because Geany doesn't know where Python lives on your system. We'll 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:\\Python34\\python' followed by a space, and the rest of the command. If you have 'Python 34', with a space between *Python* and *34*, Geany will not be able to run your code. Also, make sure your capitalization matches what you see here exactly.\n", "\n", " C:\\Python34\\python -m py_compile \"%f\"\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:\\Python34\\python \"%f\"\n", "Test your setup by running *hello.py* again.\n", "\n", "### Python 2\n", "\n", "If you installed Python 2.7 instead of Python 3, the commands you want are probably:\n", "\n", " C:\\Python27\\python -m py_compile \"%f\"\n", "and\n", "\n", " C:\\Python27\\python \"%f\"\n", "### Troubleshooting\n", "\n", "If Geany still can't 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": [ "- - -\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": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }