It turns out that inline display (and probably even generating the image in the first place) was failing because matplotlib was unable to load the Vera.ttf
font file. It attempted to load that file from the wrong file system location, one that wasn't accessible to the process, which was running in an OS X sandbox.
10/29/13 11:59:02.000 PM kernel[0]: Sandbox: python(24173) deny file-read-data $HOME/Library/Developer/Xcode/DerivedData/IPython_Notebook-adcshxaaibpeztbztvthgauvufsx/Build/Products/Debug/IPython Notebook.app/Contents/Resources/virtualenv/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
The process was running from this location:
$HOME/Library/Developer/Xcode/DerivedData/IPython_Notebook-adcshxaaibpeztbztvthgauvufsx/Build/Products/Release/IPython Notebook.app
("Debug" vs "Release")
After I trashed the Debug location and relaunched the app, the sandbox message went away and the inline plotting started to work. When I copied the application bundle to yet another location and launched it from there, it failed again. The stack trace in the sandbox violation report indicates that it's FreeType that tries to load the font from the old location:
0 libsystem_kernel.dylib 0x00007fff9054f5da __open + 10
1 libfreetype.dylib 0x000000010b789214 FT_Stream_New + 260
2 libfreetype.dylib 0x000000010b789e00 FT_Open_Face + 144
3 libfreetype.dylib 0x000000010b789d5e FT_New_Face + 46
4 ft2font.so 0x000000010b7259f0 FT2Font::FT2Font(Py::PythonClassInstance*, Py::Tuple&, Py::Dict&) + 698
5 ft2font.so 0x000000010b735fa6 Py::PythonClass<FT2Font>::extension_object_init(_object*, _object*, _object*) + 116
Some investigation revealed that matplotlib maintains a fontList.cache
file, which ends up in the app's sandbox container directory. After the app bundle is moved, the paths in that cache file are invalid/inaccessible. I added code to my app to remove this cache file at launch.
So not really an IPython issue, but I thought I'd post this in case it helps somebody who also embeds the notebook in a sandboxed OS X app in the future.
%pylab inline
instead of the--pylab=inline
andfrom pylab import *
calls?--pylab
and%pylab
are being deprecated and replaced by--matplotlib
and%matplotlib
, respectively.import matplotlib.pyplot as plt;plt.plot([1,2]),display(plt.gcf())
?