1. 程式人生 > >jupyter notebook自動補全功能實現

jupyter notebook自動補全功能實現

Jupyter notebook使用預設的自動補全是關掉的。要開啟自動補全,需修改預設配置。

 

命令列中輸入:ipython profile create

以上命令會在~/.ipython/profile_default/目錄下生成ipython_config.py和ipython_kernel_config.py

 

我們需要修改(ipython_config.py)的以下幾行,將開啟補全功能:

## Activate greedy completion PENDING DEPRECTION. this is now mostly taken care
#  of with Jedi.
#
#  This will enable completion on elements of lists, results of function calls,
#  etc., but can be 
unsafe because the code is actually evaluated on TAB. c.Completer.greedy = True ## Experimental: restrict time (in milliseconds) during which Jedi can compute # types. Set to 0 to stop computing types. Non-zero value lower than 100ms may # hurt performance by preventing jedi to build its cache. c.Completer.jedi_compute_type_timeout
= 400 ## Experimental: Use Jedi to generate autocompletions. Off by default. c.Completer.use_jedi = True

重啟jupyter後生效。

 

注:以上操作後,在編寫程式碼是發現不是自動不全,是要按下tab鍵才可以補全,所以還是有些不便,還好有外掛,通過Hinterland外掛即可解決自動補全問題了,安裝配置步驟:

1、在命令列中啟用程式碼補全環境(注:如果使用的是預設環境則不需要啟用)

2、安裝nbextensions(以下不截圖了,在cmd環境中執行即可,在安裝過程中如有提示缺少的庫安裝即可)

pip install jupyter_nbextensions_configurator

jupyter nbextensions_configurator enable –user

3、重啟jupyter,在彈出的主頁面裡,能看到增加了一個Nbextensions標籤頁,在這個頁面裡,勾選Hinterland即啟用了程式碼自動補全。

注:如果頁面無Hinterland項,或者不全,命令列執行:

jupyter contrib nbextension install --user --skip-running-check

再次重啟jupyter,Nbextensions標籤頁中資料將全部出現了

 

 在輸入程式碼後,會自動補全了,不用再按tab鍵了,快很多了吧