Deploying JupyterHub for Education

Over the last few months, I’ve been busily working on converting a class that I am a TA for from Matlab to Python. Actually, not just Python, but IPython/Jupyter notebooks! Part of this involved setting up a server that the students could log in to in order to complete their assignments. I wrote a post over on the Rackspace developer blog about it:

I’ve also been busy developing a tool called nbgrader for grading IPython notebooks. More on this in a future post, hopefully!

How I Learned to Stop Worrying and Love PyCon

Ok, I’ll admit it. I was pretty nervous about going to PyCon. I was giving a talk, I was only going to know a couple of people there, I was going for an entire week, and it was going to be in a city where they speak a language of which I only know about two words. Also, I was a bit unsure of what to expect in terms of the social climate (especially given that the only other non-academic tech conference I’ve been to has been DEFCON, which is not exactly known for being low on sexism).

I shouldn’t have worried, though. PyCon was phenomenally awesome! I met a million amazing people and the talks were exceptionally well done. Everyone was incredibly friendly and outgoing, so much that I rarely found time not to talk to people! I have to say that PyCon is easily the best conference I’ve ever been to (even better than last year’s CogSci, which was also pretty great). Here’s a recap.

Installing 64-bit Panda3D for Python 2.7 on OS X

I use the Panda3D video game engine to develop experiments for my research. I needed to install a development version that included some bugfixes, but unfortunately, installing Panda3D on OSX is not the easiest task to accomplish. The development builds they provide are unfortunately only 32-bit, but I needed to be able to run my Panda3D code alongside libraries like NumPy, which I had installed as 64-bit (which is the default on OSX). For a while, I tried to get NumPy/SciPy/etc. installed for 32-bit, but failed, and ultimately was able to get Panda3D compiled for 64-bit Python 2.7. Here are the steps that I took in order to compile it; hopefully they will be useful to others (and at the very least, a reference for myself going forward!)

Rewriting Python Docstrings With a Metaclass

Update: I gave a talk based on this post at the November 2013 San Francisco Python meetup! Here are the slides and a video of the talk.

Today, I found myself in a situation where I had a few different classes inheriting from each other, e.g.:

Inheritance structure
class A(object):
    def foo(self):

class B(A):

class C(B):

Specifically, each of these classes was a test class that I was running using noseB and C had different setup methods than A, but otherwise ran the same test. However, nosetests -v doesn’t print out the name of the method’s class, only the docstring, which is of course the same for all three classes. This made it very difficult to tell which method was actually failing.

To resolve this, I wrote a metaclass to intercept each class at creation time and rewrite its docstrings to be prefixed with the name of the class. This was probabily overkill, but I’d been itching to play around with metaclasses for a while and decided this was a semi-valid excuse.

On Collecting Data

When collecting data, how do you save it?

There are about a million different options. In Python, you can choose from many different libraries:

  • pickle
  • numpy
  • yaml
  • json
  • csv
  • sql

… just to name a few. Over time I’m fairly certain that I’ve managed to save data (whether behavioral or simulation) in all of these formats. This is really inconsistent: it makes it difficult to know what encoding any particular dataset is in, let along the format of the data itself, and it means I end up writing and rewriting code to do saving, loading, parsing, etc., more times than I ought to.

Switching to Octopress

As you may be able to tell, the look of this site has drastically changed. I’ve been meaning to overhaul the theme for a while, and I decided I also wanted to try something different from Wordpress. In particular, I wanted more flexibility with embedding code, which Octopress seems to be particularly good at:

Hello, World!
def hello_world():
    print "Hello, World!"


Also, I just really like how Octopress blogs look by default. I’ve been fiddling with the theme on this today, and I’ll probably continue to fiddle with it going forward. Because Octopress serves static content, I feel like I have somewhat more control over the look and feel of my blog – and importantly, I can try out changes locally before deploying them, which was not something I could do with Wordpress.

Hurray for change and learning new tools!

Why Is Making a Git Commit So Complicated?

I’ve realized that I don’t blog very often because I tend to write very long and thorough posts. In an effort to try to start blogging more, I’m going to let myself off the hook some of the time and just write about something short. Perhaps this will get me more in the habit of writing, which will then lead to more in-depth posts!

Anyway, today in our lab meeting I gave a presentation on using git. As I was working on the presentation the past few days, I struggled with a way to answer a question which I’ve been asked multiple times:

Why does it take so many steps to make a commit?

Macs and Emacs

In my last post, I talked about how to set up Emacs as a Python IDE. Since then, two things have changed:

  • I got a Macbook Air. Switching from Linux to Mac required a few (mostly minor) changes to my Emacs configuration.
  • I have begun using the fabulous IPython Notebook, which has really helped me organize my code and streamline my workflow.

In this post I’ll tell you how switching to a Mac has affected my configuration. In a future post (coming soon!), I’ll talk about the IPython Notebook, how I set it up for my configuration, and how it’s really improved my Python development environment. You can find the emacs configuration associated with this post here.

Emacs as a Python IDE

Update 04/08/2014: It seems like this post has been helpful for a lot of people, which really makes me happy! I just wanted to let new readers coming by know that the configuration I present in this post is out-of-date. However, I have my Emacs configuration on GitHub, and do try to keep it up-to-date. If you have any difficulties getting the configuration in the GitHub to work, please do submit a bug request and I will try to help you fix the problem.

As I mentioned in last week’s post, I am a heavy Emacs user and find it invaluable as an environment for my research. In particular, I use Emacs most for data analysis and modeling in Python, including an interface to IPython, which allows me to quickly switch between writing and running snippets of code. This proves to be a great replacement MATLAB, at least in my opinion.

I frequently get requests for my .emacs configuration file or questions about how I have such an environment set up. As such, in this post I’m going to document how to set up your Emacs configuration to support rapid Python development, including the plugins I have installed and the keyboard shortcuts I use most often.

Note that I am running GNU Emacs 23.3.1 (x86_64-pc-linux-gnu, GTK Version 2.24.5). I have never tried running it under OSX or Windows, so I can’t guarantee that these instructions will transfer, but you are welcome to try. If you run into any inconsistencies, feel free to send them to me and I will update this post accordingly!

Also, if you are new to Emacs, please read my beginner’s guide first, as I will be assuming familiarity with basic Emacs functionality and terminology. I will also assume you can at least read and understand LISP to some extent (but you don’t necessarily have to be able to write it).