Jupyter NoteBook运行配置

什么是Jupyter NoteBook

1
Jupyter Notebook, 以前又称为IPython notebook,是一个交互式笔记本, 支持运行40+种编程语言. 可以用来编写漂亮的交互式文档.

检测Python系统版本并升级

1
2
3
4
5
6
7
# 检测 python 版本信息
python --version
Eg: Python 3.9.5

# 升级
python -m pip install --upgrade pip

更换pip 镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 创建 pip 文件夹
C:\Users\[coderitl 用户名]\pip[自行新建 pip 文件夹]

#创建文件
pip.ini

# 文件内容
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/ # 更换可选择下列地址
[install]
trusted-host = mirrors.aliyun.com # 更换可选择下列地址

# 其他镜像源
中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/
清华: https://pypi.tuna.tsinghua.edu.cn/simple
阿里云: https://mirrors.aliyun.com/pypi/simple/
华中理工大学: https://pypi.hustunique.com/
山东理工大学: https://pypi.sdutlinux.org/

安装、运行、配置: Jupyter NoteBook

  • 安装

    1
    pip install jupyter
  • 运行

    1
    jupyter notebook
    • 运行方式

      运行jupyter

  • 配置Jupyter NoteBook 打开默认目录

    1
    2
    3
    4
    5
    # 获取配置文件目录
    进入 Windows(cmd->dos)命令行界面,输入: jupyter notebook --generate-config 命令后会返回配置文件路径

    # 使用相应记事本打开,修改如下,之后保存关闭
    在文件中搜索 notebook_dir
    • 修改为如下信息

      修改jupyter默认打开路径

  • 创建一个文件

    在jupyter中创建python文件

  • 运行

    运行python文件,快捷键ctrl+Enter

  • 主题配置

    • 安装主题

      1
      pip install jupyterthemes
    • 显示主题列表

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      ➜ ~  jt -l
      Available Themes:
      chesterish
      grade3
      gruvboxd
      gruvboxl
      monokai
      oceans16
      onedork
      solarizedd # 墨绿
      solarizedl # 淡黄
      ➜ ~ ✗
    • 设置主题字体字体大小, 宽度

      1
      2
      3
      4
      5
      # 设置
      jt -t onedork -f fira -fs 12 -cellw 96% -ofs 12 -dfs 12 -T

      # 恢复默认主题
      jt -r
      • 效果

        onedark主题

      • 添加如下样式信息【C:\Users\coderitl\.jupyter\custom

        custom

        • 样式预览

          默认住题样式预览

        • 样式添加

          1
          2
          3
          4
          5
          div.CodeMirror-code{   
          font-family: "consolamono";
          font-size: 12px;
          line-height: 36px;
          }
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        31
        32
        33
        34
        .CodeMirror pre {
        font-family: Consolas;
        font-size: 12pt;
        }

        * {
        font-family: Consolas;
        }

        div.output_area pre {
        font-family: Consolas;
        font-size: 12pt;
        }

        div.input_prompt {
        font-family: Consolas;
        font-size: 12pt;
        }

        div.out_prompt_overlay {
        font-family: Consolas;
        font-size: 12pt;
        }

        div.prompt {
        font-family: Consolas;
        font-size: 12pt;
        }

        span.cm-comment {
        font-family: Consolas !important;
        font-style: normal !important;
        color: #BB3D00 !important;
        }
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        * {font-family: Consolas;}
        /*Markdown 单元格字体的大小*/
        .text_cell_render{
        font-size: 12pt;
        line-height: 24px;
        letter-spacing: 1px;
        font-style: normal !important;
        /* font-family: san francisco, "PingFangSC-Medium" !important; */
        }
        /*修改的是注释的字体样式与大小还有,字体*/
        span.cm-comment {
        font-family: san francisco, "PingFangSC-Medium", "Microsoft YaHei" !important;
        font-size: 12pt;
        font-style: normal !important;
        /*color:#BB3D00 !important;*/
        }

        /*这里修改的是Code里的方字大小*/
        pre.CodeMirror-line{
        font-family: Consolas, "PingFangSC-Medium", "Microsoft YaHei";
        font-size: 20px !important
        }

        /* 输出结果 */
        div.output pre {
        font-family: Consolas, "PingFangSC-Medium", "Microsoft YaHei";
        line-height: 20px;
        -webkit-font-smoothing: antialiased !important;
        font-size: 12pt;
        }

        效果展示

        1
        jt -t monokai -T -N -fs 13 -f consolamono

        monokai主题

    • 配置快捷提示【anaconda 中的jupyter 扩展不会显示】

      1
      2
      python -m pip install jupyter_contrib_nbextensions
      jupyter contrib nbextension install --user --skip-running-check