Skip to content

人工智能训练师环境安装指南

1. 准备工作

系统环境选择

方式说明优缺点
直接安装 Python在本地系统安装 (推荐)速度快,安装体积小;过程略复杂
容器方式运行使用 Docker 运行不影响系统环境,极简配置;需安装容器,纯命令行操作
  • 推荐操作系统: Windows 11 / MacOS 14+ / Ubuntu / CentOS
  • 推荐 Python 版本: 3.13.x (2025年9月以后版本均可)

2. 安装 Python

Windows 篇

  1. 检查已有安装: 打开命令提示符 (cmd),输入 where python。如果不是需要的版本 (如 3.13.7),建议全部卸载后重新安装。

  2. 下载安装包: 访问 Python 官网,在 "Downloads" 页面找到 "Stable Releases",下载对应系统的 64位 安装程序。

    • 考试指定版本 (旧): Python 3.9.7
    • 课程推荐版本 (新): Python 3.13.7
  3. 运行安装程序:

    • 双击运行安装包。
    • 务必勾选 "Add python to PATH" (添加环境路径)。
    • 点击 "Install Now" 开始安装。
    • 在弹出的提示框中,选择“是”以禁用路径最长字符限制
  4. 验证安装: 在命令提示符中输入 python --version,如果正确显示 Python 版本号,则表示安装成功。

macOS 篇

  1. 打开“终端” (Terminal)。
  2. 输入 python3 并回车。如果未安装,系统会自动弹出开发者工具安装窗口,点击“安装”即可。

3. 安装依赖包

使用 pip 命令安装

Windows 用户一键安装命令

使用管理员身份打开命令行,输入以下完整命令:

bash
pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pandas=2.3.3 matplotlib seaborn Pillow==8.4.0 openpyxl xlrd onnxruntime scikit-learn xgboost opencv-python==4.10.0.84 imblearn notebook==6.4.5 traitlets==5.9.0

macOS 用户分批安装命令

打开终端,分别复制以下命令执行。如果出错,可尝试将 == 和后面版本号删除后再试一次。

bash
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pandas=2.3.3
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com matplotlib
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com seaborn
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com Pillow==8.4.0
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com openpyxl
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com xlrd
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com onnxruntime
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com scikit-learn
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com xgboost
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com opencv-python==4.10.0.84
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com notebook
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com traitlets==5.9.0
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com imblearn
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com jupyter

4. 启动 Jupyter

启动 Jupyter Notebook

在命令行中输入:jupyter notebook 并回车。

启动 JupyterLab

在命令行中输入:jupyter lab 并回车。

macOS 用户启动方式

在终端中输入:python3 -m notebook 并回车。

顺利启动后,系统会自动在默认浏览器中打开 Jupyter 主界面,表示环境配置成功。

5. 常见问题

问题 1:Jupyter 启动时不自动打开浏览器或报错

解决方法

  1. 以管理员身份打开命令行,输入以下命令生成配置文件:
    bash
    jupyter notebook --generate-config
  2. 根据你的操作系统,找到配置文件:
    • Windows: C:\Users\你的用户名\.jupyter\jupyter_notebook_config.py
    • macOS: /Users/你的用户名/.jupyter/jupyter_notebook_config.py
  3. 用记事本或文本编辑器打开该文件。
  4. 找到 c.ServerApp.use_redirect_file = True 这一行,将其修改为 c.ServerApp.use_redirect_file = False
    • 注意: 确保该行没有# 注释掉,且顶格书写
  5. 保存文件并重新启动 Jupyter。

6. 容器方式运行 (可选)

如果你偏好使用 Docker,一条命令即可启动已配置好的环境(需提前安装 Docker)。

bash
docker run --name trainer \
  -d -v $PWD:/app \
  -p 8888:8888 \
  registry.cn-hangzhou.aliyuncs.com/django-pub/ai-trainer

环境总结与上课前的准备

  • 二选一: 根据设备和工作特点,选择本地安装、容器。
  • 熟练掌握: 确保重启电脑后,能顺利再次启动 Jupyter 环境。
  • 上课前必须做到:
    1. 能够正常启动 Jupyter Notebook/JupyterLab。
    2. 了解 Jupyter 启动后打开的目录对应电脑中的实际文件夹位置。
    3. 已根据本文指引成功安装所有依赖类库。
    4. 已安装好 Office 或 WPS,能正常打开 .docx.xlsx 文件。