{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "###### The cell below loads the style of this notebook." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.core.display import HTML\n", "css_file = '../styles.css'\n", "HTML(open(css_file, \"r\").read())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Installing and Using Python\n", "-------------------------------------------------------------" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Learning Objectives

\n", "
\n", "
\n", "\n", "> - Install Python and a large range of 3rd party modules on your laptop\n", "> - Show you how to use Python on the University's Managed Desktop Machines\n", "> - Introduce you to the different ways of running Python\n", "> - A brief introduction to the Jupyter notebook\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Installing Python on your laptop\n", "--------------------------\n", "\n", "There are many ways and places to obtain Python. I strongly recommend downloading and installing the Anaconda Python distribution. As well as installing the Python language and it's standard library, the Anaconda package also installs most of the modules and libraries needed for scientific computing. \n", "\n", "Point your web-browser at the [Anaconda download page](http://continuum.io/downloads) and download the correct version for your machine. \n", "\n", "\n", "\n", "Make sure you click on the correct O/S, and be sure to click the \"I want Python 3.x\" link to get the installer for Python 3 and not Python 2! Then follow the installation instructions for your O/S at http://docs.continuum.io/anaconda/install.html." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Task

\n", "
\n", "
\n", "\n", "> If you've brought a laptop along with you, try and install Anaconda Python now. Place your green sticky note on your screen when you're done. If you get stuck, place a red sticky note on your screen.\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Python on CiCS Machines\n", "-----------------------------------------------------------------\n", "\n", "There is a version of Anaconda Python on the CiCS machines. This only works on 64-bit Windows so may not be available anywhere, but can be installed using the software centre.\n", "\n", "Take a look in the windows start menu. Click on \"All Programs\". If there is a menu item called \"Anaconda (64-bit)\", it is already installed. If there is a menu item called \"Anaconda Python\", you have an out-of-date Python2 package. Do not use this!\n", "\n", "If your Python is out of date, or there is no Python installed on your machine you can install the package called \"Anaconda-Python-3 - Install\" via the software centre" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Task

\n", "
\n", "
\n", "\n", "> If you're using the managed desktop, see if your Anaconda Python is up-to-date now. If not, install it via the software centre. Place your green sticky note on your screen when you're done. If you get stuck, place a red sticky note on your screen.\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# The astro Python server\n", "-----------------------------------------------------------------\n", "\n", "For the practical sessions associated with PHY241, and the homeworks associated with those sessions, you'll be running Python on a server. You should have received a username and password for this server - if not see Stu Littlefair [(email)](mailto:s.littlefair@shef.ac.uk).\n", "\n", "This server is located at http://astrolabpy.shef.ac.uk. If you don't have a laptop, or couldn't run Python on the managed desktop, you should log into this server now, so that you can follow along with the tasks during the bootcamp.\n", "\n", "\n", "# Three ways to run Python\n", "-----------------------------------------------------------------\n", "\n", "### 1. The IPython command-line interpreter\n", "### 2. Editing Python (.py) files\n", "### 3. The Jupyter notebook\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "## 1. The IPython command-line interpreter\n", "\n", "It is launched from the command-line. This is familiar to Linux/Unix users. Perhaps not so much for those used to Mac or Windows machines. To start the command line\n", "\n", "* Mac OS/X: In Finder/Applications, search for \"Terminal\"\n", "* Linux/Unix: Ctrl-Alt-t\n", "* Windows: Start Menu -> Anaconda (64 bit) -> Anaconda Python 3\n", "* Astro Python Server: Click New -> Terminal from the toolbar on the top-right\n", "\n", "\n", "\n", "Type ```ipython``` at the command-line to start the interpreter\n", "\n", "\n", "\n", "Any python commands you type into the interpreter will be executed. For example, type ```print( \"Hello World!\" )```\n", "\n", "\n", "\n", "To close the terminal, either type ```exit()``` or Ctrl-d.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Exercise

\n", "
\n", "
\n", "\n", "> Start the IPython interpreter on your machine, and get Python to print your name to the screen\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "The interpreter is most useful when you want to do some testing of an idea, or a quick calculation. The IPython interpreter has really nice [features](http://ipython.org/ipython-doc/3/interactive/tutorial.html), like **tab-completion of code**, and exensive **help** features (type help, or enter a question mark after the name of an object). Look at the URL above for more info.\n", "\n", "If you want to write complex programs to execute later, you are better off writing Python (.py) files. \n", "\n", "\n", "## 2. Editing Python (.py) files\n", "\n", "Editing Python files requires using a text editor. The best ones will highlight your code for you and make it easier to read. I recommend Nedit for Linux, TextWrangler or SublimeText for Mac OS X and NotePad or, NotePad++ or SublimeText for Windows (**Notepad++ can be installed via the software centre on CiCS machines**).\n", "\n", "Creating a Python file is easy. Open your editor, write in the code you want to execute, and save it with a .py extension. In the example below I've used TextWrangler on OS X to save a file called ```hello_world.py```\n", "\n", "\n", "\n", "To run the commands in the file, simply start a command-line session (see above) and type, for example, ```python hello_world.py```\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Exercise

\n", "
\n", "
\n", "\n", "> Create a file called \"hello_world.py\" containing the Python statements to print out your name. Save it and execute it using Python on your system \n", "\n", "> *Note: those of you using the astro Python server won't be able to try this!*\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. The Jupyter notebook\n", "\n", "The Jupyter notebook (formerly known as the IPython notebook) is a really nice way of running Python commands. It allows you to mix Python code, text comments, image display and nicely formatted equations. These notes were themselves written in the Jupyter notebook.\n", "\n", "You can start a notebook session from the command line by typing ```jupyter notebook```. Your web browser will open to an interactive notebook page. This is the same webpage you get when you log into the astro Python server. On CiCS machines, the notebook is launched from the start menu (All Programs -> Anaconda (64-bit) -> IPython (Py 3.4) Notebook).\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Conclusions

\n", "
\n", "
\n", "\n", "> * We've installed Python on our own machines\n", "> * We've discussed different ways of running Python\n", "> * Coming next - a detailed look at the Jupyter Notebook" ] } ], "metadata": { "kernelspec": { "display_name": "IPython (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 }