JupyterNotebook插件管理与安装

JupyterNotebook插件管理与安装

1.JupyterNotebook简介

​ The Jupyter Notebook interface is a Web-based application for authoring documents that combine live-code with narrative text, equations and visualizations.

​ Jupyter Notebook是基于网页的用于交互计算的应用程序。其可被应用于全过程计算:开

发、文档编写、运行代码和展示结果。——Jupyter Notebook官方介绍

2.JupyterNotebook插件管理

​ JupyterNotebook本身有推荐的插件管理包,首先需要安装如下第三方库用于管理JupyterNotebook插件。

pip install jupyter_nbextensions_configurator
pip install jupyter_contrib_nbextensions

jupyter_nbextensions_configurator安装
JupyterNotebook插件管理与安装_第1张图片
jupyter_contrib_nbextensions安装
JupyterNotebook插件管理与安装_第2张图片

安装完成后,我们还需要执行如下命令来完成插件管理启用:

jupyter nbextensions_configurator enable --user
jupyter contrib nbextension install --user

3.JupyterNotebook常用插件

3.1 Codefolding

This extension enables the CodeMirror feature to allow codefolding in code cells

可以折叠代码块,当代码多的时候,保持代码整洁性。
JupyterNotebook插件管理与安装_第3张图片

3.2 Variable Inspector

The Variable Inspector extension collects all defined variables and display them in a floating window. The extension is also draggable, resizable, collapsable. 在右上角出现变量表。
JupyterNotebook插件管理与安装_第4张图片

3.3 Scratchpad

Adds a scratchpad cell to Jupyter notebook.

打开一个便签,可以在当前内核上运行代码,但是不用再当前添加cell。使用 Shift + Enter 打开便签本,然后通过 Ctrl + B 将其关闭。

JupyterNotebook插件管理与安装_第5张图片

3.4 Table of Contents (2)

The toc2 extension enables to collect all running headers and display them in a floating window, as a sidebar or with a navigation menu. The extension is also draggable, resizable, collapsable, dockable and features automatic numerotation with unique links ids, and an optional toc cell.

打开后会在左侧出现目录。

JupyterNotebook插件管理与安装_第6张图片

3.5 Hinterland

Enable code autocompletion menu for every keypress in a code cell, instead of only enabling it with tab. 代码补全

3.6 Autopep8

Use kernel-specific code to reformat/prettify the contents of code cells # 代码补全功能

autopep8插件选中之后,使用时报错,报错信息如下图:

JupyterNotebook插件管理与安装_第7张图片

解决办法:(tf_2.5_py_3.7) C:\Users\hbwhx>conda install autopep8
JupyterNotebook插件管理与安装_第8张图片

4.JupyterNotebook中kernel切换

Q:jupyter notebook running kernel in different env?

如何在jupyter notebook中在不同的环境中使用kenrel?

# solution
# This is a tricky part of ipython / Jupyter. The set of kernels available are independent of what your virtualenv is when you start jupyter Notebook. The trick is setting up the the ipykernel package in the environment you want to identify itself uniquely to jupyter. From docs on multiple ipykernels.

source activate ENVNAME
pip install ipykernel
python -m ipykernel install --user --name ENVNAME --display-name "Python (whatever you want to call it)"
This is a tricky part of ipython / Jupyter. The set of kernels available are independent of what your virtualenv is when you start jupyter Notebook. The trick is setting up the the ipykernel package in the environment you want to identify itself uniquely to jupyter. From docs on multiple ipykernels,

source activate ENVNAME
pip install ipykernel
python -m ipykernel install --user --name ENVNAME --display-name "Python (whatever you want to call it)"

#  If you only want to have a single Python 3 kernel, from the conda environment, just use python -m ipykernel install --user and it will reset the default python to the one in the virtualenv.

实际操作

JupyterNotebook插件管理与安装_第9张图片

# 激活conda环境 tf_2.5_py_3.7
activate tf_2.5_py_3.7

在这里插入图片描述

# 安装 ipykernel 模块
pip install ipykernel

JupyterNotebook插件管理与安装_第10张图片

# 将指定的虚拟环境添加到kernel(ipython)
python -m ipykernel install --user --name tf_2.5_py_3.7 --display-name "tf_2.5_py_3.7"(在jupyter中显示的kernel名称)

在这里插入图片描述

​ 设置成功后,就能在 jupyter notebook 中看到自己的 kernel了。其他kernel 的添加也可以按照此法进行。
JupyterNotebook插件管理与安装_第11张图片

你可能感兴趣的:(jupyter,Notebook,python)