{ "metadata": { "name": "", "signature": "sha256:a271b28c47f7b047472835ac1b0e5553feafc8231c54469b46c1251f72dac7a4" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "# - compatibility with Python 3\n", "from __future__ import print_function # print('me') instead of print 'me'\n", "from __future__ import division # 1/2 == 0.5, not 0" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting code for the exercises with git" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Change to your home directory:\n", "\n", "```\n", "cd\n", "```\n", "\n", "Change to the `pna_code` directory:\n", "\n", "```\n", "cd pna_code\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check that all is calm and well in this, your git repository:\n", "\n", "```\n", "git status\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you see any changes with `git status`, investigate with `git diff`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you like the changes, add them, and commit them:\n", "\n", "```\n", "git add my_file_with_changes.py\n", "git commit\n", "```\n", "\n", "Now your own text editor should open up for you to type a message." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get all the information about the class repository. First confirm you have a git *remote* for the class repository:\n", "\n", "```\n", "git remote -v\n", "```\n", "\n", "Next fetch all the information from this (and any other) remote:\n", "\n", "```\n", "git fetch --all\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, create and checkout the branch for today's class:\n", "\n", "```\n", "git branch for-class-day9 class-repo/for-class-day9\n", "git checkout for-class-day9\n", "```\n", "\n", "You should see a file in the working directory called `rotations.py`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Putting stuff on the Python path" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remember the Python path?" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import sys\n", "print('\\n'.join(sys.path))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are going to be using the modules in `pna_code` again this week.\n", "\n", "It is getting a little tiring to keep doing:\n", "\n", "```\n", "import sys\n", "sys.path.append('/Users/mb312/pna_code')\n", "```\n", "\n", "Is there any easier way?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Why yes - there is. In fact there are several.\n", "\n", "The one we are going to use is the `PYTHONPATH` environment variable (see https://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### If you are on a Mac" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Open `Terminal.app`;\n", "* Open the file `~/.bash_profile` in your text editor;\n", "* Add the following line to the end:\n", "\n", " ```\n", " export PYTHONPATH=$HOME/pna_code\n", " ```\n", "\n", " Save the file.\n", "* Close `Terminal.app`;\n", "* Start `Terminal.app` again, and type this:\n", "\n", " ```\n", " echo $PYTHONPATH\n", " ```\n", "\n", " It should show something like `/Users/your_username/pna_code`. If not, come get one of us." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### If you are on Linux" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Open your favorite terminal program;\n", "* Open the file `~/.bashrc` in your text editor;\n", "* Add the following line to the end:\n", "\n", " ```\n", " export PYTHONPATH=$HOME/pna_code\n", " ```\n", " Save the file.\n", "* Close your terminal application;\n", "* Start your terminal application again, and type this:\n", "\n", " ```\n", " echo $PYTHONPATH\n", " ```\n", "\n", " It should show something like `/home/your_username/pna_code`. If not, come get one of us." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### If you are on Windows" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Got to the Windows menu, right-click on \"Computer\" and select \"Properties\": \n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From the computer properties dialog, select \"Advanced system settings\" on the left:\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From the advanced system settings dialog, choose the \"Environment variables\" button:\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the Environment variables dialog, click the \"New\" button in the top half of the dialog, to make a new *user* variable:\n", "\n", "\n", "\n", "Give the variable name as `PYTHONPATH` and the value is the path to the `pna_code` directory. Choose OK and OK again to save this variable." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now open a `cmd` Window (Windows key, then type `cmd` and press Return). Type:\n", "\n", "```\n", "echo %PYTHONPATH%\n", "```\n", "\n", "to confirm the environment variable is correctly set:\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want the IPython notebook to see this new `PYTHONPATH` variable, you may need to close your terminal, open it again, and restart `ipython notebook`, so that it picks up `PYTHONPATH` from the environment settings." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can check the current setting of environment variables, using the `os.environ` dictionary:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import os\n", "os.environ['PYTHONPATH']" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }