Coding Environments

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:

Jupyter Notebook (IPython): (Recommended for this class)

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.

Project Jupyter is a spinoff project of IPython that provides a modern, online interface for IPython:

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.

Installation

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:

# Activate your TensorFlow environment, if you haven't already: 
# 'source activate tensorflow' --or-- 'activate tensorflow', depending on OS and your environment name
conda install jupyter

If you didn't install Anaconda but already have Python, Jupyter is easily pip installable:

# NOTICE: Only do this if you didn't already install Anaconda
pip3 install --upgrade pip
pip3 install jupyter

Launching

To open, switch to your working directory and type the following into your terminal/command prompt:

jupyter notebook

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.

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.

Use

*Note: Keyboard shortcuts can be used to perform many common tasks in Jupyter. These can be found at Help > Keyboard Shortcuts

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 >.

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):

Code cells

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.

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.

Markdown cells

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.

Additional Resources

More info on Jupyter here: http://jupyter-notebook.readthedocs.io/en/latest/

Spyder

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:

Installation

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:

# Activate your TensorFlow environment, if you haven't already: 
# 'source activate tensorflow' --or-- 'activate tensorflow', depending on OS and your environment name
conda install spyder

Alternatively, you can go to Tools>PYTHONPATH Manager, click Add Path, and enter in the path to your Anaconda environment.

If you didn't install Anaconda but already have Python, Spyder is easily pip installable:

# NOTICE: Only do this if you didn't already install Anaconda
pip3 install --upgrade pip
pip3 install spyder

Launching

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:

spyder

Additional Resources

More info here: http://pythonhosted.org/spyder/

Text editors: Vim, Emacs, Sublime, Notepad++, gedit, nano, etc.

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:

python [your_python_file].py

This will run your_python_file.py with your default Python version.

If this is your default preference, I'm guessing you probably don't need my help with installation or usage.