Jupyter 安装使用教程

今天给大家分享的是Jupyter安装和基本使用教程
同时在我安装的过程中遇到了一些问题,解决方法,一并和大家分享
学习交流,欢迎关注:极简XksA
微信账号:xksnh888

一、Jupyter介绍

      Jupyter Notebook 的本质是一个 Web 应用程序,便于创建和共享文学化程序文档,支持实时代码,数学方程,可视化和 markdown。用途包括:数据清理和转换,数值模拟,统计建模,机器学习等等。优点:好用,很好用。

二、安装

  • 1.安装方法,windows下,cmd 中直接使用 pip 安装
pip install juputer

注:Jupyter安装需要Python 3.3或更高版本,或Python 2.7。

# 升级
pip3 install --upgrade pip

安装过程比较漫长,大概需要5min左右。

  • 2.安装完成后运行
jupyter 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这个模块找不到,于是我跑到目录Python36\Lib\site-packages\markupsafe下,果然,没有_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 sys
PY2 = sys.version_info[0] == 2
if 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的一个特性:可以修改之前的单元格,对其重新计算,这样就可以更新整个文档了

  • 3.一些基本操作(gif动图演示)
    这里写图片描述
    还有很多功能给大家自己开发吧,欢迎评论留言,说出你还知道的Jupyter的其他功能。

猜你喜欢

转载自blog.csdn.net/qq_39241986/article/details/80715140