So I decided to do machine learning using Scikit-learn. I also decided to use matplotlib because I wanted to visualize the figure. When I imported pylab to use matplotlib easily, I got the error RuntimeError: Python is not installed as a framework, so I changed the matplotlib settings and solved the problem.
$ pip install scikit-learn $ brew install freetype $ sudo pip install python-dateutil $ sudo pip install pyparsing $ sudo pip install matplotlib
To install matplotlib
Is necessary. There are many other things you need. For more information, please visit the Official Page
If you brew install freetype, the dependent libpng will also be included.
In a dialogue environment
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.
First, I checked if there were any people who were in trouble with the same error and who solved it.
Discussion on a project using matplotlib called yt http://hg.yt-project.org/yt/issue/642/cannot-import-pylab-on-os-x-using
Japanese blog article that ran into the same problem http://asahima.hatenablog.com/entry/2013/10/11/201119
matplotlib issues on the original github https://github.com/matplotlib/matplotlib/issues/2361
Apparently it hasn't been resolved yet as of October 2013.
The matplotlib image drawing backend (reference http://matplotlib.org/faq/usage_faq.html#what-is-a-backend) is "macosx" which renders using Cocoa's API by default. GTK Agg and Qt4Agg are non-default backends. When using from Linux or Windows, of course, set a backend other than macosx.
The problem is that in my environment I used pyenv to install Python 3.3 in a different location than it was originally on my OSX system. In this case, it may not be possible to draw with Cocoa's API, so when importing pylab, an error will occur just in case.
Specifying the backend to something other than macosx solves the problem.
Since you installed matplotlib with pip, you should have a directory called ~ / .matplotlib. Create a file called matplotlibrc there.
backend : TkAgg
And specify to use TkAgg as the backend.
How to write matplotlibrc Reference http://matplotlib.org/users/customizing.html
I ran the code that visualizes the result of sklearn in pylab, which is introduced in this blog article http://sucrose.hatenablog.com/entry/2013/05/25/133021, in an interactive environment.
from sklearn.datasets import load_digits import pylab as pl digits = load_digits() pl.gray() pl.matshow(digits.images) pl.show()
In this way, I was able to draw a beautiful figure even with TkAgg.