简说Python,号主老表,Python终身学习者,数据分析爱好者,从18年开始分享Python知识,原创文章227篇,写过Python、SQL、Excel入门文章,也写过Web开发、数据分析文章,老表还总结整理了一份2022Python学习资料和电子书资源,关注后私信回复:2022 即可领取。

写在前面

今天给大家分享的是Jupyter安装和基本使用教程

这是我6月10日在csdn上写的一篇博客,最近很多小伙伴都说Jupyter很好用,就不乏有一些小伙伴不知道怎么安装使用,所以把之前的博文编辑了一下,发给大家。

分享内容主要包括:我安装的过程中遇到了一些问题,解决方法和Jupyter基本使用。

一、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]

默认会自动跳转到页面(网页)

image.png

Jupyter起始页面

三、基本使用

  • 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文件,如下动图演示:

image.png

新建项目

而且大家可以看到,我第一次输入 2+3 ,按 Shift + Enter 键运行,得出结果 5 ,然后还可以把上面的输入更改,改为 2+5 ,再运行,也能得出结果,这也是 Jupyter 的一个特性: 可以修改之前的单元格,对其重新计算,这样就可以更新整个文档了

  • 3.一些基本操作(gif动图演示)

image.png

基本操作

还有很多功能给大家自己开发吧,欢迎评论留言,说出你还知道的Jupyter的其他功能。

image.png

数据挖掘基础学习一:VMware虚拟机Ubuntu上安装Python和IPython Notebook(Jupyter Notebook)完整步骤及需要注意的问题(以ubuntu-18.04.3为例)
数据挖掘基础学习一:VMware虚拟机Ubuntu上安装Python和IPython Notebook(Jupyter Notebook)完整步骤及需要注意的问题(以ubuntu-18.04.3为例)
Jupyter 工具的安装与使用方法,jupyter运行python代码演示,好用的python编辑器推荐!
Jupyter 工具的安装与使用方法,jupyter运行python代码演示,好用的python编辑器推荐!