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鍵了,快很多了吧