菜鸟笔记
提升您的技术认知

Jupyter Notebook基础(1)简介、安装、运行服务器

简介

Jupyter是一个开源项目,脱胎自IPython项目,目的是创建功能强大的交互式解释器(REPL)。

Jupyter 项目架构图如下,可以简单认为IPython为整个Jupyter 项目提供编程语言(内核)层面的支持,而Jupyter ConsoleJupyter QtConsoleJupyter Notebook只是用户交互界面。

因此可以将Jupyter Notebook理解为一个基于Web的增强交互式解释器UI(网站),依托IPython它可以安装一些语言支持,初始阶段只支持Python语言(IPython),现在还可以安装Julia、R内核(解释器)。

Jupyter Notebook特点是可以将代码、公式、可视化结果等结合在一个可分享的文档中,主要应用于数据科学和科学计算。

JupyterLab是下一代Jupyter Notebook的用户界面。

安装

conda:
conda install -c conda-forge notebook
pip:
pip install notebook

运行环境

Jupyter Notebook作为Web应用,运行于网页浏览器中,目前支持ChromeFirefoxSafari以及使用chromium内核的EdgeOpera浏览器。

运行服务器

jupyter notebook是基于tornadoZeroMQ开发的,可以简单理解为一个动态网站,那么运行jupyter notebook必须先运行Web服务器。

在命令行中输入jupyter notebook并回车即可运行Jupyter Notebook 服务器,运行成功后Jupyter Notebook将会在浏览器中打开Web UI(Jupyter内部称其为dashboard)。
注意!在Jupyter Notebook 服务运行状态下,dashboard是可以关闭的,可通过URL或本地文件再次打开dashboard

与此同时,控制台会显示服务的相关信息:

# 说明Jupyter Notebook保存路径,此处为C:\Users\Administrator
[I 22:52:10.317 NotebookApp] Serving notebooks from local directory: C:\Users\Administrator
# 说明Jupyter Notebook 服务器地址,此处为http://localhost:8888/或http://127.0.0.1:8888/
[I 22:52:10.317 NotebookApp] The Jupyter Notebook is running at:
[I 22:52:10.318 NotebookApp] http://localhost:8888/?Token=41b5f0e4c5e7ec596a2e8c9662b859de4c32e4cd7290e791
[I 22:52:10.319 NotebookApp]  or http://127.0.0.1:8888/?token=41b5f0e4c5e7ec596a2e8c9662b859de4c32e4cd7290e791
# 在控制台按CTRL+C会停止Jupyter Notebook服务器
[I 22:52:10.319 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 22:52:10.443 NotebookApp]
# 在不停止Jupyter Notebook服务器的前提下,可以通过以下三种方式再次打开Jupyter Notebook
    To access the notebook, open this file in a browser:
        file:///C:/Users/Administrator/AppData/Roaming/jupyter/runtime/nbserver-10848-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=41b5f0e4c5e7ec596a2e8c9662b859de4c32e4cd7290e791
     or http://127.0.0.1:8888/?token=41b5f0e4c5e7ec596a2e8c9662b859de4c32e4cd7290e791