LoginSignup
16
1

More than 3 years have passed since last update.

【解決済み】Jupyter NotebookでTab補完が出来ない。。。原因はJedi(ジェダイ)のフォースが暗黒面に。。。(嘘)

Last updated at Posted at 2021-01-28

:warning: 2021/3現在以下のバージョンではこの問題は解決済みです。
* Python 3.8.3
* Jpyter 1.0.0
* Jedi 0.18.0

事の経緯

筆者はPythonで開発を行う時にPipenvで環境の切り分けを毎回行っています。最初は面倒くさいと思っていましたが、慣れるととても便利で気に入っています。先日Jupyter Notebookを使える環境を作って喜々としてJupyterを起動してNotebookを作成しました。ところが、怪しい挙動に見舞われました。ライブラリをインポート使用とimpoと入力してTabキーを打鍵してもTab補完が出来ません。。。

jupyter

原因の究明

最初はPC内の処理が重くてなかなk補完が出ないのかと思っていましたが、待てど暮らせど出て来ません。Jupyterを再起動しようとターミナルに戻ると以下の様なエラーが表示されていました。

実際のエラー表示
[I 14:14:31.852 NotebookApp] Jupyter Notebook 6.2.0 is running at:
[I 14:14:31.852 NotebookApp] http://localhost:8888/?token=c5ac034a93761e5e38d0b6043e3f51aa61ede0947a935dbb
[I 14:14:31.852 NotebookApp]  or http://127.0.0.1:8888/?token=c5ac034a93761e5e38d0b6043e3f51aa61ede0947a935dbb
[I 14:14:31.852 NotebookApp] サーバを停止し全てのカーネルをシャットダウンするには Control-C を使って下さい(確認をスキップするには2回)[C 14:14:31.889 NotebookApp] 

    To access the notebook, open this file in a browser:
        file:///Users/user/Library/Jupyter/runtime/nbserver-21142-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=c5ac034a93761e5e38d0b6043e3f51aa61ede0947a935dbb
     or http://127.0.0.1:8888/?token=c5ac034a93761e5e38d0b6043e3f51aa61ede0947a935dbb
[I 14:14:38.996 NotebookApp] Creating new notebook in 
[I 14:14:40.717 NotebookApp] Kernel started: 42a9eb0c-a578-49c8-980d-c71bf41f9273, name: python3
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/ipykernel/kernelbase.py", line 265, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/tornado/gen.py", line 762, in run
    value = future.result()
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/tornado/gen.py", line 234, in wrapper
    yielded = ctx_run(next, result)
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/ipykernel/kernelbase.py", line 580, in complete_request
    matches = yield gen.maybe_future(self.do_complete(code, cursor_pos))
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/ipykernel/ipkernel.py", line 356, in do_complete
    return self._experimental_do_complete(code, cursor_pos)
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/ipykernel/ipkernel.py", line 381, in _experimental_do_complete
    completions = list(_rectify_completions(code, raw_completions))
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/IPython/core/completer.py", line 484, in rectify_completions
    completions = list(completions)
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/IPython/core/completer.py", line 1818, in completions
    for c in self._completions(text, offset, _timeout=self.jedi_compute_type_timeout/1000):
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/IPython/core/completer.py", line 1861, in _completions
    matched_text, matches, matches_origin, jedi_matches = self._complete(
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/IPython/core/completer.py", line 2029, in _complete
    completions = self._jedi_matches(
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/IPython/core/completer.py", line 1373, in _jedi_matches
    interpreter = jedi.Interpreter(
  File "/Users/user/.local/share/virtualenvs/test-MRRjzm7v/lib/python3.8/site-packages/jedi/api/__init__.py", line 725, in __init__
    super().__init__(code, environment=environment,
TypeError: __init__() got an unexpected keyword argument 'column'
[I 14:16:40.863 NotebookApp] Saving file at /Untitled.ipynb

ネットで色々と調べて見たところGitHub上で議論されていました。議論によるとNotebookで補完を担っているJedi(ジェダイ)の最新版(Ver.0.18.0)に問題(バグ)が有る様です。Jedi Ver.0.17.2を利用すれば現在の所バグは発生しない様です。

実際にJedi Ver.0.17.2をインストールしてみる

実際にJedi Ver.0.17.2をインストールして再度Jupyter Notebookを起動してみます。筆者の環境ではPipenvを用いているのでpipenv install jedi==バージョン番号でインストール出来ました。pipなど別のコマンドを用いてる場合はそのコマンドに合わせたインストールコマンドを実行します。

pipenv install jedi==0.17.2

Jupyter Notebookの再起動

Jupyter Notebookを再起動します。そしてTab補完を試しました。今度は正しく補完されました。エラーも出ていません。

jupyter restart

[I 14:29:00.768 NotebookApp] Jupyter Notebook 6.2.0 is running at:
[I 14:29:00.768 NotebookApp] http://localhost:8888/?token=1060ea919a5036907778b675b60638d9ec208ebee7a9103d
[I 14:29:00.768 NotebookApp]  or http://127.0.0.1:8888/?token=1060ea919a5036907778b675b60638d9ec208ebee7a9103d
[I 14:29:00.768 NotebookApp] サーバを停止し全てのカーネルをシャットダウンするには Control-C を使って下さい(確認をスキップするには2回)[C 14:29:00.790 NotebookApp] 

    To access the notebook, open this file in a browser:
        file:///Users/user/Library/Jupyter/runtime/nbserver-22055-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=1060ea919a5036907778b675b60638d9ec208ebee7a9103d
     or http://127.0.0.1:8888/?token=1060ea919a5036907778b675b60638d9ec208ebee7a9103d
[W 14:29:05.876 NotebookApp] Notebook Untitled.ipynb is not trusted
[I 14:29:06.199 NotebookApp] Kernel started: aaeb58b6-3e67-47ac-90bb-958888bb6793, name: python3

これで解決しました。タイトルはJedi(ジェダイ)ライブラリに起因したバグだったのでスターウォーズネタに絡めた単なる洒落です。。。決して以下の人物とは関係ありません。。。

Darth Vader
画像はWikipediaより

16
1
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
16
1