Jupyter Notebook 安装指南
前置条件
Jupyter 依赖 Python 环境(3.8 及以上版本最佳),需先安装 Python。
一、安装 Python 环境
1. 检查是否已装 Python
python --version
# 部分 Mac 系统可能需要使用 python3 --version
- 如果输出
Python 3.8.x/3.9.x/3.10.x→ 跳过'安装 Python',直接装 Jupyter - 如果提示'不是内部命令' → 按下面步骤装 Python
2. 安装 Python(未安装时)
Windows 系统
- 下载地址:https://www.python.org/downloads/windows/(选 3.10.x 版本,稳定)
- 安装时必须勾选:
Add Python 3.10 to PATH(最关键,否则终端找不到 Python) - 点击
Install Now,等待安装完成 - 验证:重新打开命令提示符,输入
python --version,能显示版本即成功
macOS 系统
- 验证:终端输入
python3 --version推荐用 Homebrew(Mac 开发者必备),终端输入:
# 先装 Homebrew(如果没装)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# 装 Python
brew install python3
Linux 系统(Ubuntu/CentOS)
# Ubuntu
sudo apt update && sudo apt install python3 python3-pip -y
# CentOS
sudo yum install python3 python3-pip -y
# 验证
python3 --version
二、安装 Jupyter
1. 升级 pip(避免安装失败)
# Windows
python -m pip install --upgrade pip
# Mac/Linux
python3 -m pip install --upgrade pip
2. 安装 Jupyter
# Windows
pip install jupyter
# Mac/Linux
pip3 install jupyter
- 等待安装完成(可能需要 1-2 分钟,看网络),出现
Successfully installed jupyter即成功。
3. 验证 Jupyter 安装
jupyter --version
能显示 jupyter core 版本号,说明安装成功。
三、启动 Jupyter Notebook
1. 启动命令
jupyter notebook
- 执行后,终端会输出日志,同时自动弹出浏览器页面(地址通常是
http://localhost:8888/)。 - 如果没自动弹浏览器,复制终端里的
http://localhost:8888/?token=xxx链接,手动粘贴到浏览器。
2. 验证启动成功
浏览器页面会显示 Jupyter 的主界面(左侧是当前目录的文件,右上角有 New 按钮),说明启动成功。
3. 新建第一个 Python 文件
- 点击右上角
New→ 选择Python 3; - 会打开一个空白的笔记本(
.ipynb文件); - 在代码框里输入
print("Hello Jupyter!"); - 点击代码框左侧的
▶️ Run按钮; - 下方会输出
Hello Jupyter!,说明能正常运行代码。
四、常见问题与解决方案
问题 1:Windows 提示'jupyter 不是内部命令'
- 原因:Python 的 Scripts 目录没加入环境变量;
- 解决:
- 找到 Python 安装目录(比如
C:\Users\你的用户名\AppData\Local\Programs\Python\Python310\Scripts); - 把这个路径添加到系统环境变量
Path里; - 重启命令提示符,重新执行
jupyter notebook。
- 找到 Python 安装目录(比如
问题 2:Mac/Linux 安装后提示'找不到 jupyter'
- 解决:用
~/.local/bin/jupyter notebook启动,或把~/.local/bin加入环境变量。
问题 3:启动时端口 8888 被占用
解决:指定其他端口启动:
jupyter notebook --port 8889
问题 4:安装速度慢/超时
解决:用国内镜像源安装:
# Windows
pip install jupyter -i https://pypi.tuna.tsinghua.edu.cn/simple
# Mac/Linux
pip3 install jupyter -i https://pypi.tuna.tsinghua.edu.cn/simple

