机器学习笔记之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 @   时光飞逝,逝者如斯  阅读(1136)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示