LoginSignup
2
2

More than 3 years have passed since last update.

Polynoteをインストールしてみる

Posted at

ScalaとPythonの両方を同時に使えるJupyter Notebookみたいな「Polynote」というソフトウェアをインストールしてみました。

PythonのノートとScalaのノートを作れるのではなく、1つのノートにPythonとScalaを混在できるんです!

Polynoteの公式サイト
Polynote | The polyglot Scala notebook

Polynoteの紹介記事
Netflix’s Polynote is a New Open Source Framework to Build Better Data Science Notebooks | by Jesus Rodriguez | DataSeries | Aug, 2020 | Medium

インストール手順

  1. Pythonをインストール
  2. Javaをインストール
  3. Polynoteをインストール
  4. Polynoteのノートから使いたいパッケージをインストール
  5. Polynoteを起動

1. Pythonをインストール

Python3をインストールします。今回はpyenvで3.8.1をインストールしました。

pyenvで普通にPythonをインストールすると、このあとのPolynote本体インストール時の pip install -r ./requirements.txt で次のようなエラーが発生しました。Polynoteが依存する jep というパッケージのビルドに失敗するようです。

    /usr/bin/ld: /home/xxxx/.pyenv/versions/3.8.1/lib/libpython3.8.a(floatobject.o): relocation R_X86_64_PC32 against symbol `PyFloat_Type' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: final link failed: bad value
    collect2: error: ld returned 1 exit status
    error: command 'gcc' failed with exit status 1

理屈がよくわからないのですが、以下のようにオプションをpyenvに付けてインストールしたら、エラーを回避できました。

$ PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v --force 3.8.1

2. Javaをインストール

Java 11をインストールします。

公式ドキュメントによるとJavaは8と11をサポートしているとのことですが、11がよいです。

最初私は8で動かしました。しかし、起動はするものの、コマンドライン上にもブラウザ上にも多くのエラーメッセージが出て、特にScalaのコレクションフレームワークは使い物になりません。AbstractMethodErrorNullPointerException などが多発します。

3. Polynoteをインストール

$ wget 'https://github.com/polynote/polynote/releases/download/0.3.11/polynote-dist.tar.gz'
$ tar xvzf polynote-dist.tar.gz  
$ cd polynote
$ pip install -r ./requirements.txt

4. Polynoteのノートから使いたいパッケージをインストール

好きにパッケージをインストールします。

$ pip install matplotlib

5. Polynoteを起動

$ python ./polynote.py

[INFO]   Loading configuration from config.yml
[INFO]   Loaded configuration: PolynoteConfig(Listen(8192,127.0.0.1),KernelConfig(None,None),Storage(tmp,notebooks,Map(),Wal(false)),List(),List(),Map(),None,Behavior(true,Always,List()),Security(None,None),UI(/),Credentials(None),Map(),StaticConfig(None,None))
[WARN]   Polynote allows arbitrary remote code execution, which is necessary for a notebook tool to function.
   |     While we'll try to improve safety by adding security measures, it will never be completely safe to
   |     run Polynote on your personal computer. For example:
   |
   |     - It's possible that other websites you visit could use Polynote as an attack vector. Browsing the web
   |       while running Polynote is unsafe.
   |     - It's possible that remote attackers could use Polynote as an attack vector. Running Polynote on a
   |       computer that's accessible from the internet is unsafe.
   |     - Even running Polynote inside a container doesn't guarantee safety, as there will always be
   |       privilege escalation and container escape vulnerabilities which an attacker could leverage.
   |
   |     Please be diligent about checking for new releases, as they could contain fixes for critical security
   |     flaws.
   |
   |     Please be mindful of the security issues that Polynote causes; consult your company's security team
   |     before running Polynote. You are solely responsible for any breach, loss, or damage caused by running
   |     this software insecurely.
[INFO]
   |       _____      _                   _
   |      |  __ \    | |                 | |
   |      | |__) |__ | |_   _ _ __   ___ | |_ ___
   |      |  ___/ _ \| | | | | '_ \ / _ \| __/ _ \
   |      | |  | (_) | | |_| | | | | (_) | ||  __/
   |      |_|   \___/|_|\__, |_| |_|\___/ \__\___|
   |                     __/ |
   |                    |___/
   |
[INFO]   Polynote version 0.3.11
[INFO]   Server listening on http://localhost:8192/

ブラウザで8192番ポートにアクセスすると、Jupyter Notebookとちょっと違う雰囲気の画面になって、ノートを作成できます。

以下は実行例です。PythonとScalaを混在できます。

image.png

2
2
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
2
2