Jupyter Notebook入门教程

1. 安装与配置

1.1 Jupyter参考网址

Jupyter官方网址

IPython官方网址

配套notebook文件下载 ,下载解压notebook.zip文件,在notebook目录下打开jupyter notebook。

1.2 安装Jupyter

  • 打开Anaconda的命令提示窗口,创建新的虚拟环境
    •   # 将env_name替换成你的自定义环境名称
        conda create -n env_name python=3.8 scikit-image=0.18 -y
        
      1
      2
      3
      4
      ![](/posts/6e4fa609/image-20250903215107797.png "image-20220531145543128")
      - ```
      # 查看新环境是否已经创建成功
      conda env list

  • 安装Jupyter
    •   # 进入新创建的环境
        conda activate env_name
        # 安装Jupyter
        pip install jupyter
        
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
       ![](/posts/6e4fa609/image-20250903215107845.png "image-20220531150241632")
      - 输入jupyter notebook即可在浏览器中自动打开notebook
      ![](/posts/6e4fa609/image-20250903215107861.png "image-20220531150716817")
      - 如果我们想新建一个notebook,并且使用当前新建的环境时,我们发现没有当前新建环境的 [IPython](https://so.csdn.net/so/search?q=IPython&spm=1001.2101.3001.7020) 内核:
      ![](/posts/6e4fa609/image-20250903215107877.png "image-20220531151013639")
      - 在当前环境下建立新的IPython内核
      - ```
      # 安装ipykernel
      pip install ipykernel
      # 生成ipykernel的配置文件
      python -m ipykernel install --name env_name
      # 查看已有的kernel
      jupyter kernelspec list


- 再次启动jupyter notebook发现已经有了当前环境下的IPython内核了

1.3 安装扩展

扩展官方文档

Github地址

1
2
3
4
5
# 安装扩展包
pip install jupyter_contrib_nbextensions
# 安装 javascript和css文件
jupyter contrib nbextension install --user
# 启动juputer notebook

发现多了 Nbextensions

然后取消勾选下面的这个选项就可以使用扩展了

下面时几个比较有用的扩展

1
2
3
4
5
6
7
8
variable inspector
table of content
snippets
codefolding
autopep8
hide input
split cell notebook
zenmode

1.4 基本配置

  • 命令行配置
    • 可以使用 jupyter notebook --help 查看配置选项
  • 配置文件配置
    •   # 生成配置文件
        jupyter notebook --generate-config
        # 配置文件的位置
        ~/.jupyter                    # linux系统
        C:\Users\<UserName>\.jupyter  # windows系统
        conda12345
      


- 打开配置文件,jupyter_notebook_config.py,里面的内容默认全部注释掉,例如想要修改默认打开的本地目录,找到 c.NotebookApp.notebook_dir

- 保存后重启即可生效。