2014年12月14日

pandas14とgoogle-api-python-clientを同時に入れたらpandasがimportできなくなった

google-api-python-clientとpandasを一緒に入れると、バージョンによってはpandasがimportできなくなるらしい。

import pandas as pd

cannot import name hashtable
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
 in ()
----> 1 import pandas as pd

中略

TypeError: expected string or buffer

ちょっと残念なバグが原因らしい
https://github.com/pydata/pandas/commit/403f38da35ab04d3997f61db3c98134fe02910d3

もしこの世界に型さえあれば、こんなバグは出なかったのに(静的型付言語原理主義)。

で、現在では解消されているのでpandasをupgradeすることに。

pip install --upgrade pandas

これでpandasを0.15.2に上げたら、とりあえず環境A(/usr/local配下にソースからpythonを入れている)では動くようになった。

ところがCanopyで入れている環境ではまた別のエラーが出た。パッケージインストーラからやらないといけなかっただろうか。

/home/user/Enthought/Canopy_64bit/User/bin/../lib/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3)

下記ページを見ながら対応

http://stackoverflow.com/questions/21011235/rpy2-fails-in-enthought-canopy-conflicting-with-internal-gfortran-libraries

$ cd ~/Enthought/Canopy_64bit/User/lib/
$ locate *gfortran.so.3* | grep /usr/lib

# 上のコマンドで出てきたlibgfortran.so.3.0.0を確認してリンクを貼る
$ ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0 libgfortran.so.3

これで解消。でもこの後、matplotlib周りでも問題が起きたので結局Canopyを入れ直した。