机器学习笔记之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

按照如下配置

 

posted @ 2021-01-12 18:41  时光飞逝,逝者如斯  阅读(979)  评论(0编辑  收藏  举报