Mac Python users, if you’ve used pip to install Numpy or SciPy from the Python Package Index recently, you may have noticed that it downloads a .whl file and skips all the old familiar compilation steps.

$ pip install scipy
Collecting scipy
  Downloading scipy-0.15.1-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (19.8MB)
    100% |################################| 19.8MB 1.1MB/s
Installing collected packages: scipy

Successfully installed scipy-0.15.1

The .whl file is a wheel, the new standard Python distribution format. Wheels have advantages.

  1. Faster installation for pure python and native C extension packages.
  2. Avoids arbitrary code execution for installation. (Avoids setup.py)
  3. Installation of a C extension does not require a compiler on Windows or OS X.
  4. Allows better caching for testing and continuous integration.
  5. Creates .pyc files as part of installation to ensure they match the python interpreter used.
  6. More consistent installs across platforms and machines.

SciPy’s wheel is fairly large because it includes libgfortran, not a part of OS X.

$ tar tzf ~/Downloads/scipy-0.15.1-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl | grep .dylibs
scipy/.dylibs/libgcc_s.1.dylib
scipy/.dylibs/libgfortran.2.0.0.dylib

I’m now doing the same thing for Rasterio, using the same delocate utilities. If you’ve got OS X 10.9 or 10.10, XCode is no longer required to get started with Rasterio. Just

$ pip install -U rasterio

and you’re ready to roll.

A peek in the .whl file shows that GDAL and its non-system dependencies are now included.

$ tar tzf ~/code/frs-wheel-builds/dist/rasterio-0.17.1post1-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl | grep .dylibs
rasterio/.dylibs/libgdal.1.dylib
rasterio/.dylibs/libgeos-3.4.2.dylib
rasterio/.dylibs/libgeos_c.1.dylib
rasterio/.dylibs/libjasper.1.0.0.dylib
rasterio/.dylibs/libjson-c.2.dylib
rasterio/.dylibs/libproj.0.dylib

What’s enabled in GDAL?

The new Rasterio wheels include GDAL 1.11.1 with a small starter set of formats enabled. No FileGDB, no PostGIS, no HDF, no MrSID. We’ll grow the list of formats to meet user demand.

DO NOT WANT!

Pip will fetch these wheels by default. If you have your own GDAL installation with special format drivers or want to actually benefit from the sharing of shared libraries, you can dodge the wheels by using pip’s --no-use-wheel option.

$ GDAL_CONFIG=/path/to/gdal-config pip install --no-use-wheel rasterio

The command above builds Rasterio from a source distribution using the specified gdal-config program to find the proper compile and link parameters to use your custom GDAL.

Any Python

Thanks to tools and documentation by the MacPython and SciPy communities, the Rasterio wheels should work on any Python 2.7 or 3.4, whether from Apple, python.org, MacPorts, or Homebrew. I believe this makes it some of the most accessible Python FOSS4G software for OS X yet. I’ve done the same for Fiona and Shapely and hope you’ll also try them soon.

Ping me if you encounter a packaging bug or want to suggest a format to enable, either at the Fiona-Rasterio-Shapely wheels repo or Twitter.