Fix errors if build_ext is invoked on a fresh checkout

This addresses a problem encountered in #824 .  It turns out that a fresh checkout of astropy master gives an error if you do ``python setup.py build_ext`` before doing ``python setup.py build`` or  ``python setup.py build_py``.  There are two different causes for this problem, which each of the two commits in this PR address.

@keflavich - you might try the RTD build from #824 off of this branch to see if that fixes your problem.  We want this fixed regardless, though, so merging this is not contingent on that being fixed

@iguananaut - it'd be good if you glanced over this to make sure I'm not subtly mis-interpreting some of the build_ext related code (which I believe you mostly wrote).