LoginSignup
6
4

More than 5 years have passed since last update.

BigGorilla環境の構築メモ

Last updated at Posted at 2017-07-12

やったこと

BigGorilla環境の構築
FlexMatcherのサンプルを試す

わかったこと

  • anaconda入れるためだけにpyenvを使い、環境管理はcondaでやるのが最近の定石
  • (2017年7月12時点だと)環境構築がうまくいかない
    • もともと公開されているconda環境の依存関係が壊れている
      • Anaconda Cloudから直接ymlをローカルにダウンロードしてurllibを指定している行を削除し、ファイル指定でインストールすることはできる。
    • 追記: ファイルがアップデートされて、公式ドキュメントどおり入るようになった。
  • FlexMatcherのサンプルも動かなかった
    • コード読まないと動かすの難しそう

次にやること

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
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4