1. 程式人生 > 實用技巧 >機器學習筆記之jupyter自動程式碼補全

機器學習筆記之jupyter自動程式碼補全

0x00 概述

jupyter預設程式碼自動補全是關閉的,要開啟自動補全,需修改預設配置。

0x01 通過修改jupyter配置檔案開啟程式碼自動補全(不推薦)

在WIndows開始選單中找到Anaconda,打開了Anaconda Prompt,

命令列中輸入:

ipython profile create

以上命令會在C:\User\$你的使用者名稱\.ipython\profile_default\目錄下生成ipython_config.py和ipython_kernel_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鍵才可以補全,每次還要手動tab一下。比較麻煩

0x02 通過安裝nbextensions實現程式碼自動補全(推薦)

2.1 更換Anaconda3 pip安裝資料來源

開啟Anaconda Prompt,使用命令 pip install jupyter_contrib_nbextensions ,預設是從官方源下載資料,比較慢而且容易中斷報錯;

執行如下命令將pip安裝源切換到國內阿里雲

pip install web.py -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

以下pip源可供選擇:

#阿里雲 http://mirrors.aliyun.com/pypi/simple/

#中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/ 

#豆瓣(douban) http://pypi.douban.com/simple/ 

#清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/

#中國科學技術大學http://pypi.mirrors.ustc.edu.cn/simple/

2.2安裝nbextensions

# pip install jupyter_contrib_nbextensions

# jupyter contrib nbextension install --user

2.3安裝 nbextensions_configurator

# pip install jupyter_nbextensions_configurator

# jupyter nbextensions_configurator enable --user

2.4 在Jupyter設定nbextensions

按照如下配置