Repository: statsmodels/statsmodels

Issue:
Installing with git sources on OS X Lion and Python 3.2
It looks like to be a problem with 2to3 conversion. Code in setup.py and called from there are supposed to be python version independent.

```
ackrite:statsmodels alexandre$ python setup.py install --user
Traceback (most recent call last):
  File "setup.py", line 56, in <module>
    setup(**configuration(top_path='').todict())
  File "setup.py", line 25, in configuration
    config.add_subpackage('nonparametric')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/distutils/misc_util.py", line 1002, in add_subpackage
    caller_level = 2)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/distutils/misc_util.py", line 971, in get_subpackage
    caller_level = caller_level + 1)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/distutils/misc_util.py", line 883, in _get_configuration_from_setup_py
    ('.py', 'U', 1))
  File "./nonparametric/setup.py", line 10, in <module>
    from _build import cython, has_c_compiler
  File "/Users/alexandre/Documents/soc2012/code/tools/_build.py", line 100
    except OSError, err:
                  ^
SyntaxError: invalid syntax
```



Discussion:
Other thing to fix:

```
>>> import statsmodels.api as sm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/statsmodels-0.5.0-py3.2-macosx-10.6-intel.egg/statsmodels/api.py", line 17, in <module>
    from .graphics import api as graphics
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/statsmodels-0.5.0-py3.2-macosx-10.6-intel.egg/statsmodels/graphics/api.py", line 5, in <module>
    from .factorplots import interaction_plot
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/statsmodels-0.5.0-py3.2-macosx-10.6-intel.egg/statsmodels/graphics/factorplots.py", line 3, in <module>
    from statsmodels.graphics.plottools import rainbow
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/statsmodels-0.5.0-py3.2-macosx-10.6-intel.egg/statsmodels/graphics/plottools.py", line 2, in <module>
    from matplotlib import colors
ImportError: No module named matplotlib
```

should be a conditional import, like in the other files in graphics/.


Resolving patch:
diff --git a/statsmodels/graphics/plottools.py b/statsmodels/graphics/plottools.py
--- a/statsmodels/graphics/plottools.py
+++ b/statsmodels/graphics/plottools.py
@@ -1,5 +1,4 @@
 import numpy as np
-from matplotlib import colors
 
 def rainbow(n):
     """
@@ -20,6 +19,7 @@ def rainbow(n):
     Converts from HSV coordinates (0, 1, 1) to (1, 1, 1) to RGB. Based on
     the Sage function of the same name.
     """
+    from matplotlib import colors
     R = np.ones((1,n,3))
     R[0,:,0] = np.linspace(0, 1, n, endpoint=False)
     #Note: could iterate and use colorsys.hsv_to_rgb
diff --git a/tools/_build.py b/tools/_build.py
--- a/tools/_build.py
+++ b/tools/_build.py
@@ -97,7 +97,7 @@ def cython(pyx_files, working_path=''):
             else:
                 try:
                     status = subprocess.call(['cython', '-o', c_file, pyxfile])
-                except OSError, err:
+                except OSError:
                     # Above is reported to fail on Mac OS X 10.6.8
                     # because cython is a shell alias in the terminal only
                     pkg_path = os.path.abspath(os.path.join(


Test patch:
diff --git a/statsmodels/graphics/tests/test_factorplots.py b/statsmodels/graphics/tests/test_factorplots.py
--- a/statsmodels/graphics/tests/test_factorplots.py
+++ b/statsmodels/graphics/tests/test_factorplots.py
@@ -1,12 +1,21 @@
 import numpy as np
+from nose import SkipTest
 from pandas import Series
-import matplotlib.pyplot as plt
 from statsmodels.graphics.factorplots import interaction_plot
 
+try:
+    import matplotlib.pyplot as plt
+    have_matplotlib = True
+except:
+    have_matplotlib = False
+
+
 class TestInteractionPlot(object):
 
     @classmethod
     def setupClass(cls):
+        if not have_matplotlib:
+            raise SkipTest('matplotlib not available')
         np.random.seed(12345)
         cls.weight = np.random.randint(1,4,size=60)
         cls.duration = np.random.randint(1,3,size=60)