機器學習筆記之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

按照如下配置

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM