国内网络环境下 MiniConda + Jupyter + ChromaDB 安装教程

国内网络环境下 MiniConda + Jupyter + ChromaDB 安装教程

针对国内网络环境,使用国内镜像源加速下载。

第一部分:安装 MiniConda(使用国内下载源)

步骤 1:下载 MiniConda(国内镜像)

  1. 清华大学镜像源:

    text
    https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
  2. 中国科学技术大学镜像:

    text
    https://mirrors.ustc.edu.cn/anaconda/miniconda/
  3. 推荐下载:

    • Miniconda3-py310_23.5.2-0-Windows-x86_64.exe

    • 对应 Python 3.10 版本

步骤 2:安装 MiniConda

  1. 双击运行下载的 .exe 文件

  2. 重要选项:

    • ✅ 为所有用户安装(可选)

    • ✅ 添加 Miniconda3 到系统 PATH 环境变量(必须勾选!)

    • ✅ 注册 Miniconda3 为默认 Python

  3. 点击 Install,等待安装完成

步骤 3:配置 Conda 国内镜像

打开 Anaconda Prompt(在开始菜单中搜索):

bash
# 查看当前配置
conda config --show

# 设置清华大学镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/

# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

# 可选:设置中科大镜像源(备用)
# conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
# conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/

第二部分:创建 Python 环境

步骤 1:创建新环境(使用国内源)

bash
# 创建名为 chroma-env 的 Python 3.10 环境
conda create -n chroma-env python=3.10 -y

步骤 2:激活环境

bash
conda activate chroma-env

激活后,提示符前会显示 (chroma-env)

步骤 3:配置 pip 国内镜像

bash
# 创建 pip 配置文件
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn

# 或者使用阿里云镜像
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set global.trusted-host mirrors.aliyun.com

# 查看配置
pip config list

第三部分:安装 Jupyter

步骤 1:安装 Jupyter(使用 Conda 镜像)

bash
# 安装 Jupyter Notebook
conda install jupyter notebook -y

# 安装 JupyterLab(推荐)
conda install jupyterlab -y

步骤 2:配置 Jupyter 中文支持(可选)

bash
# 安装中文语言包
pip install jupyterlab-language-pack-zh-CN

步骤 3:生成 Jupyter 配置文件

bash
# 生成配置文件
jupyter notebook --generate-config

# 设置默认浏览器(可选)
# 编辑配置文件 C:\Users\你的用户名\.jupyter\jupyter_notebook_config.py
# 添加:c.NotebookApp.browser = 'C:/Program Files/Google/Chrome/Application/chrome.exe %s'

第四部分:安装 ChromaDB 及依赖

步骤 1:安装 ChromaDB

bash
# 使用清华镜像源安装
pip install chromadb -i https://pypi.tuna.tsinghua.edu.cn/simple

# 如果失败,尝试使用豆瓣源
pip install chromadb -i https://pypi.douban.com/simple/

步骤 2:安装依赖包

bash
# 批量安装常用依赖
pip install pandas numpy matplotlib scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple

# 安装 sentence-transformers(ChromaDB 可能需要)
pip install sentence-transformers -i https://pypi.tuna.tsinghua.edu.cn/simple

# 如果 sentence-transformers 安装失败,先安装 PyTorch
# 使用国内镜像安装 PyTorch
pip install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple

# 再次尝试安装 sentence-transformers
pip install sentence-transformers -i https://pypi.tuna.tsinghua.edu.cn/simple

第五部分:备用安装方案(如果上述方法失败)

方案 A:使用离线包安装

  1. 下载离线包:

  2. 离线安装:

bash
# 进入下载目录
cd 下载目录

# 安装离线包
pip install 文件名.whl

方案 B:手动下载安装(针对特别难装的包)

bash
# 1. 从国内镜像站手动下载 whl 文件
# 2. 使用 pip 安装本地文件
pip install C:\下载路径\chromadb-0.4.6-py3-none-any.whl

第六部分:验证安装

步骤 1:创建测试脚本

创建 test_installation.py 文件:

python
print("=== 安装测试 ===")

# 测试 Python
import sys
print(f"Python 版本: {sys.version[:50]}")

# 测试 ChromaDB
try:
    import chromadb
    print(f"✅ ChromaDB 已安装,版本: {chromadb.__version__}")
except Exception as e:
    print(f"❌ ChromaDB 导入失败: {e}")

# 测试 Jupyter
try:
    import notebook
    print(f"✅ Jupyter 已安装,版本: {notebook.__version__}")
except Exception as e:
    print(f"❌ Jupyter 导入失败: {e}")

# 测试常用库
libraries = ['pandas', 'numpy', 'matplotlib', 'sklearn']
for lib in libraries:
    try:
        __import__(lib)
        print(f"✅ {lib} 已安装")
    except:
        print(f"❌ {lib} 未安装")

print("\n=== 测试完成 ===")

步骤 2:运行测试

bash
python test_installation.py

第七部分:快速使用指南

启动 Jupyter:

bash
# 1. 打开 Anaconda Prompt
# 2. 激活环境
conda activate chroma-env

# 3. 启动 Jupyter Notebook(传统界面)
jupyter notebook

# 或启动 JupyterLab(现代界面)
jupyter lab

创建快捷方式(可选):

  1. 在桌面创建 .bat 文件,内容:

bat
@echo off
call conda activate chroma-env
start jupyter lab
pause

posted on 2026-01-20 21:28  freeliver54  阅读(0)  评论(0)    收藏  举报

导航