前回に引き続き、BigGorilla環境の構築を行いました。
またFlexMatcherのサンプルを試すところまでやってみました。
BigGorilla環境の構築メモ – Qiitaから転載してます。
わかったこと
- anaconda入れるためだけにpyenvを使い、環境管理はcondaでやるのが最近の定石
(2017年7月12時点だと)環境構築がうまくいかないもともと公開されているconda環境の依存関係が壊れている
–Anaconda Cloudから直接ymlをローカルにダウンロードしてurllibを指定している行を削除し、ファイル指定でインストールすることはできる。- 追記: ファイルがアップデートされて、公式ドキュメントどおり入るようになりました。
- FlexMatcherのサンプルも動かなかった
- コード読まないと動かすの難しそう
環境
- Mac OS X 10.11 El Capitan
- homebrewはインストール済み
- pyenvを使ってanacondaをインストールする
BigGorilla環境構築(以下の情報は古いです。作業記録として残しています)
(開発環境の)pyenvが古かったので、アップデートしました。
pyenv で管理しているpythonのバージョンを更新する – Qiita
anacondaをインストール
$ pyenv install anaconda3-4.2.0
$ pyenv global anaconda3-4.2.0
BigGorillaの環境作成。。できない。
2017/07/21追記: できるようになりました。以下古い記録
$ conda env create biggorilla/py3gorilla
Collecting urllib==1.21.1
Downloading urllib-1.21.1.tar.gz (226kB)
100% |████████████████████████████████| 235kB 640kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/bx/k4yrl_bd3nb0v8pz7fm60t8r0000gp/T/pip-build-58rsg5li/urllib/setup.py", line 191
s.connect((base64.b64decode(rip), 017620))
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/bx/k4yrl_bd3nb0v8pz7fm60t8r0000gp/T/pip-build-58rsg5li/urllib/
CondaValueError: Value error: pip returned an error.
完全には入っていませんが、試しにactivateします。
source activate Py3Gorillaだとシェルが落ちます。
pyenvを使用している場合は、condaのactivateコマンドをフルパスで指定する必要があります。
Condaの使い方メモ – Qiita
データサイエンティストを目指す人のpython環境構築 2016 – Qiita
$ conda info -e
# conda environments:
#
Py3Gorilla /Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0/envs/Py3Gorilla
root * /Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0
$ source /Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0/envs/Py3Gorilla/activate Py3Gorilla
動作確認用のJupyter NoteBookを試してみましたが、Py3Gorillaのカーネルが見つからないと言われます。
$ anaconda download biggorilla/hi_gorilla
$ jupyter notebook hi_gorilla.ipynb
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-770f0b5370fe> in <module>()
----> 1 import py_stringmatching as sm
2
3 # This notebook imports a package that most users do not have installed
4 # before using BigGorilla. Running the notebook successfully implies the
5 # successful installation of BigGorilla.
ImportError: No module named 'py_stringmatching'
一旦conda env createすると、prefixが登録されているといわれてしまいあす。
消す場合はconda env remove -n します。
$ conda env create biggorilla/py3gorilla
Using Anaconda API: https://api.anaconda.org
CondaValueError: Value error: prefix already exists: /Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0/envs/Py3Gorilla
$ conda env remove -n Py3Gorilla
Package plan for package removal in environment /Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0/envs/Py3Gorilla:
The following packages will be REMOVED:
openssl: 1.0.2l-0
pip: 9.0.1-py36_1
python: 3.6.1-2
readline: 6.2-2
setuptools: 27.2.0-py36_0
sqlite: 3.13.0-0
tk: 8.5.18-0
wheel: 0.29.0-py36_0
xz: 5.2.2-1
zlib: 1.2.8-3
Proceed ([y]/n)? y
Unlinking packages ...
[ COMPLETE ]|###############################################################################| 100%
2017/07/12時点で試したところ、この方法だと以下のエラーがでて入りませんでした。
(6月にアップデートされたファイル名がおかしいせいか、古い方のymlが適用されている気がします。たぶんこれからアップデートで直ると思われます)
追記: ファイルがアップデートされて、公式ドキュメントどおり入るようになりました。
$ conda env create biggorilla/py3gorilla
Collecting urllib==1.21.1
Downloading urllib-1.21.1.tar.gz (226kB)
100% |████████████████████████████████| 235kB 640kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/bx/k4yrl_bd3nb0v8pz7fm60t8r0000gp/T/pip-build-58rsg5li/urllib/setup.py", line 191
s.connect((base64.b64decode(rip), 017620))
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/bx/k4yrl_bd3nb0v8pz7fm60t8r0000gp/T/pip-build-58rsg5li/urllib/
CondaValueError: Value error: pip returned an error.
Files :: Anaconda Cloudからymlをダウンロードしてurllibを指定している行を削除すると、インストールすることはできます。
新しい方のymlも入ることは入るがflexmatcherのバージョンが古いです(デグレしてる?)
# 一旦中途半端にできた環境を消す
$ conda env remove -n Py3Gorilla
# ローカルで修正したymlファイルを指定して、環境再作成
$ vim ~/Downloads/Py3Gorilla.yml //urllibの行を消す
$ conda env create --name test --file ~/Downloads/Py3Gorilla.yml
# pyenvを使用している場合は、condaのactivateコマンドをフルパスで指定する必要がある。source activate Py3Gorillaだとシェルが落ちる。
$ source /Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0/envs/test/bin/activate test
# 動作確認用のnotebookを落としてきて起動
$ anaconda download biggorilla/hi_gorilla
$ jupyter notebook hi_gorilla.ipynb
FlexMatcherのサンプルを試す
次にFlexMatcherのサンプルを試してみました。
サンプルのコードがついているので、ソースをコピーしてjupyter notebookに貼り付けてみます。
やってみた結果、エラーで動かないことがわかりました。
実行結果
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-34cd037abc3a> in <module>()
27 mapping_list = [data1_mapping, data2_mapping]
28 fm.create_training_data(schema_list, mapping_list)
---> 29 fm.train()
30
31 # Creating a test schmea
/Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0/envs/test/lib/python3.5/site-packages/flexmatcher/flexmatcher.py in train(self)
27 The class considers panda dataframes as databases and their column names as
28 the schema. FlexMatcher learn to do schema matching by training on
---> 29 instances of dataframes and how their columns are matched against the
30 mediated schema.
31
/Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0/envs/test/lib/python3.5/site-packages/flexmatcher/flexmatcher.py in <listcomp>(.0)
27 The class considers panda dataframes as databases and their column names as
28 the schema. FlexMatcher learn to do schema matching by training on
---> 29 instances of dataframes and how their columns are matched against the
30 mediated schema.
31
/Users/kkanazaw/.pyenv/versions/anaconda3-4.2.0/envs/test/lib/python3.5/site-packages/flexmatcher/classify.py in predict_training(self, folds)
TypeError: 'float' object cannot be interpreted as an integer
終わりに
次回は、Flexmatcherのコードを読んでみようと思います。