Python3でstatsmodelsをなんとかインストールした

はじめに

今まで統計関連のコードはRで書いてたのですが、最近はこれをPythonに置き換えようと色々なライブラリを試してます。
で、その過程でstatsmodelsをインストールしようとしたらエラーが出たんですが、なんとか解決したので、その方法を忘れないようにメモしておきます。

状況

  • Pythonのバージョンは3.4.1
  • pip3 install statsmodelsでビルドエラー

エラーログは以下のような感じ(一部抜粋)

statsmodels/tsa/kalmanf/kalman_loglike.c:7021:19: error: no member named 'f_tstate' in 'struct _frame'

        (*frame)->f_tstate = PyThreadState_GET();

        ~~~~~~~~  ^

1 warning and 1 error generated.

error: command 'clang' failed with exit status 1

解決法

以下のステップを踏むことで解決しました。

  1. pip3 install cythonで、Cythonをインストールする
  2. Cythonのバージョンが0.20.1以上であることを確認する
  3. pip3 install git+https://github.com/statsmodels/statsmodels.gitで、GitHubリポジトリからインストールする

おわりに

これで一日無駄にした

参考