今天给你们分享的是Jupyter安装和基本使用教程,同时在我安装的过程当中遇到了一些问题,解决方法,一并和你们分享python
Jupyter Notebook 的本质是一个 Web 应用程序,便于建立和共享文学化程序文档,支持实时代码,数学方程,可视化和 markdown。用途包括:数据清理和转换,数值模拟,统计建模,机器学习等等。优势:好用,很好用。web
Jupyter Notebook 也是一个算法工程师友好的工具,但仍有许多拓展的空间,好比:当你的文件中包含大量的代码和 Markdown 混排时,你可能须要一个目录来帮助你更好的对文件结构进行可视化,nbextensions 能够帮咱们实现。算法
1.安装方法,windows下,cmd 中直接使用 pip 安装chrome
pip install jupyter
注意:Jupyter安装须要Python 3.3或更高版本,或Python 2.7。windows
# 升级pip3 install --upgrade pip
安装过程比较漫长,大概须要5min左右。浏览器
2.安装完成后运行markdown
jupyter notebook
若是安装正常,可能不会出错,我这里安装时提醒我cookie
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
因此运行报错:机器学习
ModuleNotFoundError: No module named 'markupsafe._compat'
提示说markupsafe._compat这个模块找不到,因而我跑到目录Python36\Lib\site-packages\markupsafe下,果真,没有_compat这个文件,而后把markupsafe这个模块卸载了,重装,仍是不行,谷歌一下(如今好像都流行这么说了,哈哈哈),找到_compat这个文件内容:ide
# -*- coding: utf-8 -*-""" markupsafe._compat ~~~~~~~~~~~~~~~~~~ Compatibility module for different Python versions. :copyright: (c) 2013 by Armin Ronacher. :license: BSD, see LICENSE for more details. """import sys PY2 = sys.version_info[0] == 2if not PY2: text_type = str string_types = (str,) unichr = chr int_types = (int,) iteritems = lambda x: iter(x.items())else: text_type = unicode string_types = (str, unicode) unichr = unichr int_types = (int, long) iteritems = lambda x: x.iteritems()
在目录Python36\Lib\site-packages\markupsafe下建立一个新文件_compat.py,将上面内容写入,保存,而后再cmd下运行jupyther,顺畅:
C:\Users\82055\Desktop>jupyter notebook [I 17:34:01.725 NotebookApp] Writing notebook server cookie secret to C:\Users\82055\AppData\Roaming\jupyter\runtime\notebook_cookie_secret [I 17:34:02.759 NotebookApp] Serving notebooks from local directory: C:\Users\82055\Desktop [I 17:34:02.760 NotebookApp] 0 active kernels [I 17:34:02.761 NotebookApp] The Jupyter Notebook is running at: [I 17:34:02.761 NotebookApp] http://localhost:8888/?token=7d96ee52f2c5c5c451af05e15d6f6cb626b1a6783b590117 [I 17:34:02.762 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 17:34:02.764 NotebookApp]
默认会自动跳转到页面(网页)
1.修改默认目录
(1)查找jupyter配置文件路径
C:\Users\82055\Desktop> jupyter notebook --generate-config Writing default config to: C:\Users\82055\.jupyter\jupyter_notebook_config.py
(2)找到配置文件,更改默认目录
## The directory to use for notebooks and kernels. c.NotebookApp.notebook_dir = 'H:\PyCoding'
再次启动jupyter,发现主页面文件为咱们本身指定的文件夹内的文件了。(默认为电脑桌面文件)
2.新建一个python文件
咱们点击页面上的new按钮,新建一个py3文件,以下动图演示:
并且你们能够看到,我第一次输入2+3,按Shift+Enter键运行,得出结果5,而后还能够把上面的输入更改,改成2+5,再运行,也能得出结果,这也是Jupyter的一个特性:能够修改以前的单元格,对其从新计算,这样就能够更新整个文档了。
还有不少功能给你们本身开发吧,欢迎评论留言,说出你还知道的Jupyter的其余功能。
pip install jupyter_contrib_nbextensions
conda install -c conda-forge jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
打开 Jupyter Notebook,能够看到主界面餐单栏多出了 Nbextensions 选项,点击能够展开拓展程序选项:
每一个拓展程序都可以单击后查看介绍与使用方法,咱们以拓展目录为例。勾选红框中的Table of Contets (2)项目。而后新建一个项目,点击菜单栏的最右边新增的目录符号,便可显示文件目录。更多的设置能够点击左侧目录的设置按钮。
更换默认的浏览器,选择谷歌浏览器,不少360打不开的页面,更换谷歌后都能有效解决,而且确保是最新版本的google浏览器。
1.产生jupyter_notebook_config.py
文件,使用windows+r
打开cmd命令输入命令:jupyter notebook --generate-config
(注意notebook后面有空格)
在cmd界面中会提示出,jupyter_notebook_config.py
中文件的路径
2.打开jupyter_notebook_config.py
文件,在第(95-99行)找到 # c.NotebookApp.browser = ''
## Specify what command to use to invoke a web browser when opening the notebook. # If not specified, the default browser will be determined by the `webbrowser` # standard library module, which allows setting of the BROWSER environment # variable to override it. #c.NotebookApp.browser = ''
在该行代码下方增长
import webbrowser webbrowser.register('chrome', None, webbrowser.GenericBrowser( u'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')) c.NotebookApp.browser = 'chrome'
其中上面代码中C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
是google浏览器的路径地址。
3.再次打开jupyter notebook,若是默认浏览器不是google浏览器,复制本身电脑中的cmd中的http://localhost:8888/?token=74493923aa071ac11d0a797133a6736296308800110bf662
到谷歌浏览器中。