今天给大家分享的是Jupyter安装和基本使用教程
同时在我安装的过程中遇到了一些问题,解决方法,一并和大家分享
欢迎关注微信公众号:简说Python
账号:xksnh888
关注回复:1024,可以领取精选编程学习电子书籍。
关于jupyter notebook更详细、最新的安装使用说明,我更新到了新文章,推荐大家直接看这篇文章,点击前往:一文搞定Python编码环境
一、Jupyter介绍Jupyter Notebook 的本质是一个 Web 应用程序,便于创建和共享文学化程序文档,支持实时代码,数学方程,可视化和 markdown。用途包括:数据清理和转换,数值模拟,统计建模,机器学习等等。优点:好用,很好用。
二、安装注意: 本文是在Windows下使用的,除了安装,Mac系统操作与本文不一致,特别是Mac系统上启动Jupyter Notebook,你可以在第2点安装完成后运行中看到。
1.安装方法,windows下,cmd 中直接使用 pip 安装 pip install jupyter注:Jupyter安装需要Python 3.3或更高版本,或Python 2.7。
# 升级pip3 install --upgrade pip安装过程比较漫长,大概需要5min左右。
2.安装完成后运行 jupyter notebook**注意:**如果你是mac系统,你的运行命令可能需要改为:
python3 -m IPython notebook如果安装正常,可能不会出错,我这里安装时提醒我
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这个模块找不到,于是我跑到目录Python36Libsite-packagesmarkupsafe下,果然,没有_compat这个文件,然后把markupsafe这个模块卸载了,重装,还是不行,谷歌一下(现在好像都流行这么说了,哈哈哈),找到_compat这个文件内容:
# -*- 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 sysPY2 = 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()在目录Python36Libsite-packagesmarkupsafe下创建一个新文件_compat.py,将上面内容写入,保存,然后再cmd下运行jupyther,顺畅:
C:Users82055Desktop>jupyter notebook[I 17:34:01.725 NotebookApp] Writing notebook server cookie secret to C:Users82055AppDataRoamingjupyterruntimenotebook_cookie_secret[I 17:34:02.759 NotebookApp] Serving notebooks from local directory: C:Users82055Desktop[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)查找jupyter配置文件路径 C:Users82055Desktop> jupyter notebook --generate-configWriting default config to: C:Users82055.jupyterjupyter_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的一个特性:可以修改之前的单元格,对其重新计算,这样就可以更新整个文档了。
3.一些基本操作(gif动图演示)
还有很多功能给大家自己开发吧,欢迎评论留言,说出你还知道的Jupyter的其他功能。