なんか時代はjupyterらしいので乗り遅れないために家のSynology製NASで動かそうとしてみた結果。

サマリー

  • だいたいpipとgemで済む
  • rbczmq入れろではまる件については、ffi_rzmqを入れて、jupyter付属のlibzmq.soを読ませれば解決

ミニマム作業

jupyter動かすまで

ほんとパッケージ入れるだけでOK

# pip install --upgrade pip setuptools
# pip install jupyter
# jupyter notebook --ip=192.168.***.***

irubyを動かす

ポイントはffi_rzmqを入れたあと、エラーメッセージに示される読み込み先パスに、jupyter付属のlibzmq.soのsymlinkを作ること

# gem install iruby
# iruby register
# gem install ffi_rzmq

(一度jupyterを動かしてrubyを立ち上げてエラーをださせる)

For non-Windows platforms, make sure libzmq is located in this search path:
["/volume1/@entware-ng/opt/lib/ruby/gems/2.5/gems/ffi-rzmq-core-1.0.6/lib/ffi-
rzmq-core/../../ext/libzmq.so", (中略), "/usr/local/lib/libzmq.so",
"/opt/local/lib/libzmq.so", "/usr/lib64/libzmq.so"]

(pipでパッケージの場所を確認する)

$ pip show jupyter
Name: jupyter
Version: 1.0.0
Summary: Jupyter metapackage. Install all the Jupyter components in one go.
Home-page: http://jupyter.org
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.org
License: BSD
Location: /volume1/@entware-ng/opt/lib/python2.7/site-packages
Requires: nbconvert, jupyter-console, qtconsole, ipykernel, notebook, ipywidgets
Required-by:

(無害そうな /opt/local/lib/ に、libzmq.so のsymlinkを張る)

# mkdir /opt/local/lib/
# cd /opt/local/lib/
# ln -s /opt/lib/python2.7/site-packages/zmq/libzmq.so .

経過詳細

とりあえずcookpadさんの記事をみて作業を始める。

# gem install iruby
(略)
Consider installing the optional dependencies to get additional functionality:
  * pry
  * pry-doc
  * awesome_print
  * gnuplot
  * rubyvis
  * nyaplot
(略)
# pip install jupyter
(略)
    Complete output from command python setup.py egg_info:
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in

egg-infoでググるとpipを更新しようというEntwareの記事が出てきたのでやってみる。

# pip install --upgrade pip setuptools
(略)
Installing collected packages: pip, setuptools
Successfully installed pip-10.0.1 setuptools-39.2.0
# pip install jupyter
(略)
Successfully installed (略)jupyter-1.0.0 jupyter-client-5.2.3
jupyter-console-5.2.0 jupyter-core-4.4.0 (略)

で、irubyを登録しようと先ほどの記事通りいれると

# ruby register
Traceback (most recent call last):
ruby: No such file or directory -- register (LoadError)

んーたしかにrubyにregisterなんてコマンドないよな…と思ってググるとRubyでシュッとグラフを書く with Jupyter notebookの中に正しいコマンドが書いてある。 i ruby register じゃないの…wwww

# iruby register
# jupyter notebook

NASのIPアドレスをいれても接続できない…のでググるとIPアドレス指定してあげるとよいそうなので、NASのIPアドレスを設定する。

$ jupyter notebook --ip=192.168.***.***
(略)
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://192.168.***.***:8888/?token=********&token=********

ここにあるURLを入れるとjyputer繋がった! pythonは動くが、rubyを動かそうとするとエラーメッセージが連発するぞ、と。よく読むと、

You should install cztop, rbczmq or ffi_rzmq before running iruby notebook.
See README.
F, [2018-06-17T02:35:24.828905 #7533] FATAL -- : Kernel died: uninitialized
 constant IRuby::Kernel::Session

ということで、適当にググった時に見えたrbczmqとか問題なのか、と、とりあえずcztopとrbczmqを入れる。

# gem install cztop rbczmq
(略)
Fetching: rbczmq-1.7.9.gem (100%)
Building native extensions. This could take a while...
ERROR:  Error installing rbczmq:
        ERROR: Failed to build gem native extension.

    current directory:
    /volume1/@entware-ng/opt/lib/ruby/gems/2.5/gems/rbczmq-1.7.9/ext/rbczmq
/opt/bin/ruby -r ./siteconf20180617-7596-1ezzggc.rb extconf.rb
"./autogen.sh"
autogen.sh: error: could not find libtool.  libtool is required to run autogen.sh.
ZeroMQ autogen failed!
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/opt/bin/$(RUBY_BASE_NAME)
        --with-system-libs
        --without-system-libs

extconf failed, exit code 1

Gem files will remain installed in /opt/lib/ruby/gems/2.5/gems/rbczmq-1.7.9 for
inspection.
Results logged to
/opt/lib/ruby/gems/2.5/extensions/arm-linux/2.5/rbczmq-1.7.9/gem_make.out
2 gems installed

libtoolがないからなのか?と思ってEntwareのパッケージ一覧を確認するが入れても libtoolは入らないので変化がない。

ということで、エラーメッセージにあったもう1つの ffi_rzmq を試してみることにする。

# gem install ffi_rzmq
ERROR:  Could not find a valid gem 'ffi_rzmq' (>= 0) in any repository
ERROR:  Possible alternatives: ffi-rzmq
# gem install ffi-rzmq
Fetching: ffi-rzmq-core-1.0.6.gem (100%)
Successfully installed ffi-rzmq-core-1.0.6
Fetching: ffi-rzmq-2.0.6.gem (100%)
Successfully installed ffi-rzmq-2.0.6
Parsing documentation for ffi-rzmq-core-1.0.6
Installing ri documentation for ffi-rzmq-core-1.0.6
Parsing documentation for ffi-rzmq-2.0.6
Installing ri documentation for ffi-rzmq-2.0.6
Done installing documentation for ffi-rzmq-core, ffi-rzmq after 3 seconds
2 gems installed

入ったけれど、相変わらずエラーがでる。 エラーメッセージをもう少し丁寧に読むことにする。

WARNING: ::CZMQ::FFI is not available without libczmq.

Unable to load this gem. The libzmq library (or DLL) could not be found.
If this is a Windows platform, make sure libzmq.dll is on the PATH.
If the DLL was built with mingw, make sure the other two dependent DLLs,
libgcc_s_sjlj-1.dll and libstdc++6.dll, are also on the PATH.
For non-Windows platforms, make sure libzmq is located in this search path:
["/volume1/@entware-ng/opt/lib/ruby/gems/2.5/gems/ffi-rzmq-core-1.0.6/lib/ffi-
rzmq-core/../../ext/libzmq.so", "/opt/bin/libzmq.so", "/opt/bin/libzmq.so",
 "/opt/sbin/libzmq.so", "/sbin/libzmq.so", "/bin/libzmq.so", "/usr/sbin/libzmq.so",
  "/usr/bin/libzmq.so", "/usr/syno/sbin/libzmq.so", "/usr/syno/bin/libzmq.so",
  "/usr/local/sbin/libzmq.so", "/usr/local/bin/libzmq.so",
  "/var/packages/Java8/target/j2sdk-image/bin/libzmq.so",
  "/var/packages/Java8/target/j2sdk-image/jre/bin/libzmq.so", "/opt/bin/libzmq.so",
  "/opt/lib/libzmq.so", "/usr/local/lib/libzmq.so", "/opt/local/lib/libzmq.so",
  "/usr/lib64/libzmq.so"]
You should install cztop, rbczmq or ffi_rzmq before running iruby notebook. See README.

うーん、以前gitから持ってきてbuildしようとしたからそれかなと思ったが、buildができない。

というところで一度放置したのだが、あとで改めて関連記事のrbczmq の幾つかのインストール方法をmると、

jupyter が使う pyzmq は、pip install で配布されるビルド済みパッケージの中に zeromq のビルド済みライブラリを同梱していて、システムにインストールされているものは参照しない。そのため、zeromq を jupyter でしか使わない人は、思い切ってシステムに zeromq と czmq をインストールしない、という選択もありだと思う。

という表現がある。

jupyterではpythonは動作しているので、このライブラリは使えてるということになるから、 ffi-rzmq がライブラリを読もうとしている場所に、pipから入ったzeromqを置いて使わせればよい、と分かる。

前述のエラーメッセージには

For non-Windows platforms, make sure libzmq is located in this search path:
[(libzmq.soを探したパス一覧)]

がある。1番無害そうな /opt/local/lib にsymlinkを作ってみる。

# mkdir /opt/local/lib/
# cd /opt/local/lib/
# ln -s /opt/lib/python2.7/site-packages/zmq/libzmq.so .
# ls -al
total 8
drwxr-xr-x 2 root root 4096 Jun 18 01:21 .
drwxr-xr-x 3 root root 4096 Jun 18 01:21 ..
lrwxrwxrwx 1 root root   46 Jun 18 01:21 libzmq.so ->
 /opt/lib/python2.7/site-packages/zmq/libzmq.so

すると、目標にしていたサンプルコードが、ようやく動作した!

local_gems = Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
local_gems.keys.each {|gem_name| puts gem_name }