{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Coding Environments" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You are welcome to use any coding environment that you like for this tutorial, so if you have prior experience or a workflow set-up already, feel free to continue to use it. If not, a few suggestions are listed here:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Jupyter Notebook (IPython): *(Recommended for this class)*\n", "\n", "IPython is an interactive version of Python that allows users to use a shell to run chunks of Python code, as opposed to an entire Python script or program. For those familiar with MATLAB or R, it is very similar to using their console/command line, but with Python code.\n", "\n", "Project Jupyter is a spinoff project of IPython that provides a modern, online interface for IPython:\n", "\n", "![Jupyter Notebook](Figures/jupyter_notebook.png)\n", "\n", "In a Jupyter Notebook, we can mix working IPython code, markdown text, graphics, magic commands (such as lines of bash), and much more. You'll notice that many of lecture materials were prepared using Jupyter notebooks.\n", "\n", "#### Installation \n", "If you followed my previous recommendation and installed Anaconda as your Python distribution, congrats, you already have Jupyter installed! However, you need to make sure that Jupyter is installed in the same environment as TensorFlow for the demo code to work:\n", "\n", "```Shell\n", "# Activate your TensorFlow environment, if you haven't already: \n", "# 'source activate tensorflow' --or-- 'activate tensorflow', depending on OS and your environment name\n", "conda install jupyter\n", "```\n", "\n", "If you *didn't install Anaconda* but already have Python, Jupyter is easily pip installable:\n", "\n", "```Shell\n", "# NOTICE: Only do this if you didn't already install Anaconda\n", "pip3 install --upgrade pip\n", "pip3 install jupyter\n", "```\n", "\n", "#### Launching\n", "To open, switch to your working directory and type the following into your terminal/command prompt:\n", "\n", "```Shell\n", "jupyter notebook\n", "```\n", "\n", "Depending on your OS, Jupyter will either automatically open a tab with Jupyter running, or provide a local host address for you to paste into your favorite browser.\n", "\n", "In your browser, you should see your working directory appear. IPython notebooks will have a book symbol before their names and can be opened by clicking on them. New notebooks can be created by clicking on the \"New\" dropdown menu in the upper right corner.\n", "\n", "#### Use\n", "\n", "*Note: Keyboard shortcuts can be used to perform many common tasks in Jupyter. These can be found at Help > Keyboard Shortcuts\n", "\n", "Jupyter notebooks are composed of a collection of cells. New cells can be created with the \"+\" button (1), or Ctrl+A(bove) or Ctrl+B(elow). Move a selected cell relative to other cells with the arrow buttons (3). Delete a cell by either clicking the cut button (2) (Note: this is \"Cut\", so it will also copy the contents), or clicking on the side region such that the stripe of the cell turns blue (7) and typing \"d\" twice. Cells can be run by clicking on the play button (4), or with Ctrl+Enter. Various options for running multiple or all cells are also listed under Cell > and Kernel >. \n", "\n", "For this class, you'll mostly use cells containing \"Code\" or \"Markdown\", as indicated by the dropdown menu in the ribbon at the top (5):\n", "\n", "*Code cells*\n", "\n", "Cells that run code in the kernel set during the creation of the notebook. This should default to Python 3 for you, and you can verify the kernel by looking in the upper right corner (6). Code cells can contain import statements, multiple lines of Python scripts, function definitions, etc., and outputs (or errors) are shown below the cell after they are run. \n", "\n", "A note about IPython cells: the results of previously defined variables persist, *even if you delete the cells that originally defined them*; pretty important to remember, as it can be quite startling the first time you experience a variable you thought you deleted coming back from the dead. Since cells usually contain fragments of a program and can be run in any order, you need to be sure to run any pre-requisite cells first. Normally this is as simple as finding the cells that haven't been run yet, running them, and then trying again. It is good practice to put your cells in the order they should be run so that other people (or you) opening your notebook can just \"Run all cells\" and replicate your results.\n", "\n", "*Markdown cells*\n", "\n", "Cells for inserting text. These are not lines of code, but are formatted nicely when run. All of my instructions in my notebooks are written in Markdown. It's easier seen than explained, so if you're curious, you can go ahead and double-click on any cell consisting of text (including this one) to see how I wrote them. \n", "\n", "#### Additional Resources\n", "\n", "More info on Jupyter here: http://jupyter-notebook.readthedocs.io/en/latest/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Spyder\n", "\n", "Spyder is an open-source integrated development environment for Python. Spyder is a bit more traditional of an IDE compared to Jupyter; it's primarily used to write full Python (`.py`) files to be executed as scripts or programs, though an IPython console is also included. Anyone who has coded in MATLAB's IDE or RStudio should feel right at home. It looks like this:\n", "\n", "![Spyder](Figures/spyder.png)\n", "\n", "#### Installation\n", "Again, if you followed my previous recommendation and installed Anaconda as your Python distribution, you're already done; Spyder came with it! However, you need to make sure that Spyder is installed in the same environment as TensorFlow for the demo code to work:\n", "\n", "```Shell\n", "# Activate your TensorFlow environment, if you haven't already: \n", "# 'source activate tensorflow' --or-- 'activate tensorflow', depending on OS and your environment name\n", "conda install spyder\n", "```\n", "\n", "Alternatively, you can go to Tools>PYTHONPATH Manager, click Add Path, and enter in the path to your Anaconda environment.\n", "\n", "\n", "If you *didn't install Anaconda* but already have Python, Spyder is easily pip installable:\n", "\n", "```Shell\n", "# NOTICE: Only do this if you didn't already install Anaconda\n", "pip3 install --upgrade pip\n", "pip3 install spyder\n", "```\n", "\n", "#### Launching\n", "\n", "If using Anaconda, before launching, make sure to activate your environment so Spyder can find your packages. To open, type the following into your terminal/command prompt:\n", "\n", "```Shell\n", "spyder\n", "```\n", "\n", "#### Additional Resources\n", "\n", "More info here: http://pythonhosted.org/spyder/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Text editors: Vim, Emacs, Sublime, Notepad++, gedit, nano, etc.\n", "\n", "There's nothing forcing you to use an IDE specialized for Python. Python files are just text with a `.py` extension. This means that if you prefer something more lightweight, you can do all you coding in your favorite text editor, and when you're ready to run your code, in your shell:\n", "\n", "```Shell\n", "python [your_python_file].py\n", "```\n", "\n", "This will run `your_python_file.py` with your default Python version.\n", "\n", "If this is your default preference, I'm guessing you probably don't need my help with installation or usage." ] } ], "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.6.1" } }, "nbformat": 4, "nbformat_minor": 1 }