IDE之Jupyter:交互式文档Jupyter Notebook简介、安装、使用方法详细攻略

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41185868/article/details/79985781

Jupyter Notebook简介

    Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言。是IPython使用浏览器作为界面向后台的IPython服务器发送请求,并显示结果。。在本文中,我们将介绍 Jupyter notebook 的主要特性,以及为什么对于希望编写漂亮的交互式文档的人来说是一个强大工具。比较好的应用就是你拿它去生成一个 教学文档,学生们可以随时改里面的代码,你做了什么功能也非常清晰。 而且同时支持LATEX,你可以写一个特别好看的文档,像一个自带代码的MINI PAPER一样。jupyter notebook非常适合DEBUG 和教学。
     ipython笔记本,很像shell,迅速执行代码看到结果!

     在普通的 Python shell 或者在IDE(集成开发环境)如Pycharm中写代码,然后在word中写文档来说明你的项目。  这个过程很反锁,通常是写完代码,再写文档的时候我还的重头回顾一遍代码。最蛋疼的地方在于,有些数据分析的中间结果,我还的重新跑代码,然后把结果弄到文档里给客户看。    有了notebook之后,我的世界突然美好了许多,因为notebook 可以直接在代码旁写出叙述性文档,而不是另外编写单独的文档。也就是它可以能将代码、文档等这一切集中到一处,让用户一目了然。
Jupyter Notebook 已迅速成为数据分析,机器学习的必备工具。因为它可以让数据分析师集中精力向用户解释整个分析过程。
Jupyter这个名字是它要服务的三种语言的缩写:Julia,PYThon和R,这个名字与“木星(jupiter)”谐音。

Py之ipython:Python库之ipython的简介、安装、使用方法详细攻略
官方文档:https://jupyter.readthedocs.io/en/latest/install.html#id4

Jupyter Notebook安装

     pip install jupyter,装完之后, 在终端运行 jupyter notebook 即可打开jupyter notebook. 先看一个用jupyter notebook的例子。

     安装 Jupyter 的最简单方法是使用 Anaconda。该发行版附带了 Jupyter notebook。你能够在默认环境下使用 notebook。要在 conda 环境中安装 Jupyter notebook,在conda终端使用命令(以下所有命令是指conda的终端Anaconda Prompt):  conda install jupyter notebook

C:\Users\99386>pip install --upgrade jupyter
Collecting jupyter
  Downloading https://files.pythonhosted.org/packages/83/df/0f5dd132200728a86190397e1ea87cd76244e42d39ec5e88efd25b2abd7e/jupyter-1.0.0-py2.py3-none-any.whl
Collecting nbconvert (from jupyter)
  Downloading https://files.pythonhosted.org/packages/39/ea/280d6c0d92f8e3ca15fd798bbcc2ea141489f9539de7133d8fe10ea4b049/nbconvert-5.3.1-py2.py3-none-any.whl (387kB)
    100% |████████████████████████████████| 389kB 659kB/s
Requirement not upgraded as not directly required: ipykernel in f:\program files\python\python36\lib\site-packages (from jupyter) (4.8.2)
Collecting jupyter-console (from jupyter)
  Downloading https://files.pythonhosted.org/packages/77/82/6469cd7fccf7958cbe5dce2e623f1e3c5e27f1bb1ad36d90519bc2d5d370/jupyter_console-5.2.0-py2.py3-none-any.whl
Collecting notebook (from jupyter)
  Downloading https://files.pythonhosted.org/packages/c0/66/cfed59f574d03ca5f1b7c5281485a9cc9a0f21342d24e0f057572316dae5/notebook-5.5.0-py2.py3-none-any.whl (8.4MB)
    100% |████████████████████████████████| 8.4MB 130kB/s
Collecting ipywidgets (from jupyter)
  Downloading https://files.pythonhosted.org/packages/7d/24/fabc09ad81c6071159a4d12d5bfbddcbea69bd9e3b16c3250ef300c0285f/ipywidgets-7.2.1-py2.py3-none-any.whl (106kB)
    100% |████████████████████████████████| 112kB 150kB/s
Collecting qtconsole (from jupyter)
  Downloading https://files.pythonhosted.org/packages/90/ff/047e0dca2627b162866920e7aa93f04523c0ae81e5c67060eec85701992d/qtconsole-4.3.1-py2.py3-none-any.whl (108kB)
    100% |████████████████████████████████| 112kB 151kB/s
Collecting nbformat>=4.4 (from nbconvert->jupyter)
  Downloading https://files.pythonhosted.org/packages/da/27/9a654d2b6cc1eaa517d1c5a4405166c7f6d72f04f6e7eea41855fe808a46/nbformat-4.4.0-py2.py3-none-any.whl (155kB)
    100% |████████████████████████████████| 163kB 172kB/s
Requirement not upgraded as not directly required: jinja2 in f:\program files\python\python36\lib\site-packages (from nbconvert->jupyter) (2.10)
Collecting pandocfilters>=1.4.1 (from nbconvert->jupyter)
  Downloading https://files.pythonhosted.org/packages/4c/ea/236e2584af67bb6df960832731a6e5325fd4441de001767da328c33368ce/pandocfilters-1.4.2.tar.gz
Collecting mistune>=0.7.4 (from nbconvert->jupyter)
  Downloading https://files.pythonhosted.org/packages/c8/8c/87f4d359438ba0321a2ae91936030110bfcc62fef752656321a72b8c1af9/mistune-0.8.3-py2.py3-none-any.whl
Collecting testpath (from nbconvert->jupyter)
  Downloading https://files.pythonhosted.org/packages/15/19/d7bc380c479a184e4a5a9ce516e4e2a773165f89b445f7cdced83d94de25/testpath-0.3.1-py2.py3-none-any.whl (161kB)
    100% |████████████████████████████████| 163kB 174kB/s
Requirement not upgraded as not directly required: pygments in f:\program files\python\python36\lib\site-packages (from nbconvert->jupyter) (2.2.0)
Requirement not upgraded as not directly required: bleach in f:\program files\python\python36\lib\site-packages (from nbconvert->jupyter) (1.5.0)
Requirement not upgraded as not directly required: traitlets>=4.2 in f:\program files\python\python36\lib\site-packages (from nbconvert->jupyter) (4.3.2)
Collecting entrypoints>=0.2.2 (from nbconvert->jupyter)
  Downloading https://files.pythonhosted.org/packages/cc/8b/4eefa9b47f1910b3d2081da67726b066e379b04ca897acfe9f92bac56147/entrypoints-0.2.3-py2.py3-none-any.whl
Requirement not upgraded as not directly required: jupyter-core in f:\program files\python\python36\lib\site-packages (from nbconvert->jupyter) (4.4.0)
Requirement not upgraded as not directly required: jupyter-client in f:\program files\python\python36\lib\site-packages (from ipykernel->jupyter) (5.2.3)
Requirement not upgraded as not directly required: tornado>=4.0 in f:\program files\python\python36\lib\site-packages (from ipykernel->jupyter) (5.0.2)
Requirement not upgraded as not directly required: ipython>=4.0.0 in f:\program files\python\python36\lib\site-packages (from ipykernel->jupyter) (6.4.0)
Requirement not upgraded as not directly required: prompt-toolkit<2.0.0,>=1.0.0 in f:\program files\python\python36\lib\site-packages (from jupyter-console->jupyter) (1.0.15)
Collecting terminado>=0.8.1 (from notebook->jupyter)
  Downloading https://files.pythonhosted.org/packages/2e/20/a26211a24425923d46e1213b376a6ee60dc30bcdf1b0c345e2c3769deb1c/terminado-0.8.1-py2.py3-none-any.whl
Requirement not upgraded as not directly required: pyzmq>=17 in f:\program files\python\python36\lib\site-packages (from notebook->jupyter) (17.0.0)
Collecting Send2Trash (from notebook->jupyter)
  Downloading https://files.pythonhosted.org/packages/49/46/c3dc27481d1cc57b9385aff41c474ceb7714f7935b1247194adae45db714/Send2Trash-1.5.0-py3-none-any.whl
Requirement not upgraded as not directly required: ipython-genutils in f:\program files\python\python36\lib\site-packages (from notebook->jupyter) (0.2.0)
Collecting widgetsnbextension~=3.2.0 (from ipywidgets->jupyter)
  Downloading https://files.pythonhosted.org/packages/ff/fa/64acc09fc845a6b2dc0724d6f3f81e829b778ed5e9a7559567b4f19a3f4b/widgetsnbextension-3.2.1-py2.py3-none-any.whl (2.2MB)
    100% |████████████████████████████████| 2.2MB 143kB/s
Collecting jsonschema!=2.5.0,>=2.4 (from nbformat>=4.4->nbconvert->jupyter)
  Downloading https://files.pythonhosted.org/packages/77/de/47e35a97b2b05c2fadbec67d44cfcdcd09b8086951b331d82de90d2912da/jsonschema-2.6.0-py2.py3-none-any.whl
Requirement not upgraded as not directly required: MarkupSafe>=0.23 in f:\program files\python\python36\lib\site-packages (from jinja2->nbconvert->jupyter) (1.0)
Requirement not upgraded as not directly required: html5lib!=0.9999,!=0.99999,<0.99999999,>=0.999 in f:\program files\python\python36\lib\site-packages (from bleach->nbconvert->jupyter) (0.9999999)
Requirement not upgraded as not directly required: six in f:\program files\python\python36\lib\site-packages (from bleach->nbconvert->jupyter) (1.11.0)
Requirement not upgraded as not directly required: decorator in f:\program files\python\python36\lib\site-packages (from traitlets>=4.2->nbconvert->jupyter) (4.3.0)
Requirement not upgraded as not directly required: python-dateutil>=2.1 in f:\program files\python\python36\lib\site-packages (from jupyter-client->ipykernel->jupyter) (2.6.1)
Requirement not upgraded as not directly required: jedi>=0.10 in f:\program files\python\python36\lib\site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.12.0)
Requirement not upgraded as not directly required: colorama; sys_platform == "win32" in f:\program files\python\python36\lib\site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.3.9)
Requirement not upgraded as not directly required: setuptools>=18.5 in f:\program files\python\python36\lib\site-packages (from ipython>=4.0.0->ipykernel->jupyter) (38.4.0)
Requirement not upgraded as not directly required: pickleshare in f:\program files\python\python36\lib\site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.7.4)
Requirement not upgraded as not directly required: backcall in f:\program files\python\python36\lib\site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.1.0)
Requirement not upgraded as not directly required: simplegeneric>0.8 in f:\program files\python\python36\lib\site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.8.1)
Requirement not upgraded as not directly required: wcwidth in f:\program files\python\python36\lib\site-packages (from prompt-toolkit<2.0.0,>=1.0.0->jupyter-console->jupyter) (0.1.7)
Collecting pywinpty>=0.5; os_name == "nt" (from terminado>=0.8.1->notebook->jupyter)
  Downloading https://files.pythonhosted.org/packages/96/b8/fe0669423dd6a7bbac22fb56bd8a740c674f22e90fd5ecb9ac6c68789a7b/pywinpty-0.5.4-cp36-cp36m-win_amd64.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 150kB/s
Requirement not upgraded as not directly required: parso>=0.2.0 in f:\program files\python\python36\lib\site-packages (from jedi>=0.10->ipython>=4.0.0->ipykernel->jupyter) (0.2.0)
Building wheels for collected packages: pandocfilters
  Running setup.py bdist_wheel for pandocfilters ... done
  Stored in directory: C:\Users\99386\AppData\Local\pip\Cache\wheels\39\01\56\f1b08a6275acc59e846fa4c1e1b65dbc1919f20157d9e66c20
Successfully built pandocfilters
tensorflow-gpu 1.4.0 requires enum34>=1.1.6, which is not installed.
wxpy 0.3.9.8 has requirement itchat==1.2.32, but you'll have itchat 1.3.10 which is incompatible.
moviepy 0.2.3.2 has requirement decorator==4.0.11, but you'll have decorator 4.3.0 which is incompatible.
Installing collected packages: jsonschema, nbformat, pandocfilters, mistune, testpath, entrypoints, nbconvert, jupyter-console, pywinpty, terminado, Send2Trash, notebook, widgetsnbextension, ipywidgets, qtconsole, jupyter
Successfully installed Send2Trash-1.5.0 entrypoints-0.2.3 ipywidgets-7.2.1 jsonschema-2.6.0 jupyter-1.0.0 jupyter-console-5.2.0 mistune-0.8.3 nbconvert-5.3.1 nbformat-4.4.0 notebook-5.5.0 pandocfilters-1.4.2 pywinpty-0.5.4 qtconsole-4.3.1 terminado-0.8.1 testpath-0.3.1 widgetsnbextension-3.2.1

参考知乎:https://www.zhihu.com/question/46309360/answer/255087779

Jupyter Notebook使用方法

T1、控制台运行jupyter notebook,自动打开网页,点击New新建,编写代码即可!前提是控制台不能关掉,要开着
Shift+Enter 运行当前代码
1、打开本地文件

2、修改默认文件夹:先jupyter notebook  --generate-config命令找到 jupyter_notebook_config.py文件
C:\Users\99386\.jupyter\jupyter_notebook_config.py
然后修改该文件,查找notebook_dir
#c.NotebookApp.notebook_dir = '' 更改为 c.NotebookApp.notebook_dir =u'F:\\Jupyter' 

3、打开指定文件夹:前提,不要修改默认的jupyter notebook配置文件jupyter_notebook_config.py。
第一步,首先切换到指定文件夹目录下
第二步,打开dos,输入jupyter notebook即可!


4、若遇到死机等问题,选择Kernel→restart即可!



T2、详细步骤

Jupyter Notebook技巧知识点

1、     %matplotlib inline   #这条命令让奋使用matplotlib绘图,不再使用窗口展示出来,而是直接在notebook 中显示

猜你喜欢

转载自blog.csdn.net/qq_41185868/article/details/79985781