# 1. 克隆專案
git clone https://github.com/markl-a/My-AI-Learning-Notes.git
cd My-AI-Learning-Notes
# 2. 創建虛擬環境
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 3. 安裝依賴(根據需求選擇)
# 選項 A - 基礎安裝
pip install -r requirements.txt
# 選項 B - 包含機器學習
pip install -r requirements.txt -r requirements-ml.txt
# 選項 C - 包含深度學習
pip install -r requirements.txt -r requirements-dl.txt
# 選項 D - 包含 LLM 應用
pip install -r requirements.txt -r requirements-llm.txt
# 選項 E - 完整安裝(所有功能)
pip install -r requirements-full.txt
# 選項 F - 開發環境
pip install -r requirements.txt -r requirements-dev.txt# 基礎安裝
pip install -e .
# 包含可選依賴
pip install -e ".[ml]" # 機器學習
pip install -e ".[dl]" # 深度學習
pip install -e ".[llm]" # LLM 應用
pip install -e ".[dev]" # 開發工具
pip install -e ".[full]" # 完整安裝確保您的 Python 版本 >= 3.9
python --version如果版本過舊,請從 python.org 下載最新版本。
為什麼需要虛擬環境?
- 隔離項目依賴
- 避免版本衝突
- 便於管理
創建方式:
python -m venv venvconda create -n ai-learning python=3.11
conda activate ai-learning# Linux/Mac
source venv/bin/activate
# Windows (cmd)
venv\Scripts\activate.bat
# Windows (PowerShell)
venv\Scripts\Activate.ps1
# Conda
conda activate ai-learningpip install --upgrade pip setuptools wheel根據您的學習路徑選擇合適的安裝方式(見下節)。
推薦配置:
pip install -r requirements.txt -r requirements-ml.txt包含的功能:
- ✅ 數學基礎(NumPy, SciPy, Matplotlib)
- ✅ 機器學習(Scikit-learn, XGBoost, LightGBM)
- ✅ 數據處理(Pandas)
- ✅ 可視化(Matplotlib, Seaborn, Plotly)
- ✅ Jupyter Notebook
適合:
- 正在學習 1.從AI到LLM基礎/1.Math_4_ML
- 正在學習 1.從AI到LLM基礎/3.ML_&_Data_Analysis
推薦配置:
pip install -r requirements.txt -r requirements-dl.txt包含的功能:
- ✅ PyTorch 生態系統
- ✅ TensorFlow/Keras
- ✅ Hugging Face Transformers
- ✅ 計算機視覺工具(OpenCV, Pillow)
- ✅ NLP 工具(NLTK, spaCy)
- ✅ 模型訓練工具(WandB, TensorBoard)
適合:
- 正在學習 1.從AI到LLM基礎/4.DL
- 正在學習 2.深入LLM模型工程與LLM運維
注意:PyTorch GPU 版本
# CUDA 11.8
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# CUDA 12.1
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# ROCm (AMD GPU)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.7推薦配置:
pip install -r requirements.txt -r requirements-llm.txt包含的功能:
- ✅ LLM API(OpenAI, Anthropic)
- ✅ LangChain 生態系統
- ✅ 向量數據庫(ChromaDB, FAISS)
- ✅ RAG 工具
- ✅ Agent 框架
- ✅ Web 框架(FastAPI, Gradio, Streamlit)
- ✅ 文檔處理工具
適合:
- 正在學習 3.LLM應用工程/4.(RAG) 基礎
- 正在學習 3.LLM應用工程/3.Agent
- 正在學習 3.LLM應用工程/7.LLM應用部屬
需要 API 金鑰:
# 創建 .env 文件
cp .env.example .env
# 編輯 .env 文件,添加您的 API 金鑰
OPENAI_API_KEY=your-key-here
ANTHROPIC_API_KEY=your-key-here推薦配置:
pip install -r requirements-full.txt -r requirements-dev.txt包含的功能:
- ✅ 所有上述功能
- ✅ 測試工具(pytest, coverage)
- ✅ 代碼質量工具(black, ruff, mypy)
- ✅ 文檔工具(Sphinx, MkDocs)
- ✅ 性能分析工具
- ✅ Pre-commit hooks
設置 Pre-commit:
pre-commit install
pre-commit run --all-files推薦配置:
pip install -r requirements-full.txt注意:
⚠️ 這會安裝大量包(可能需要 10+ GB 空間)⚠️ 安裝時間較長(可能需要 20-30 分鐘)⚠️ 建議有足夠的網絡帶寬
A: 常見解決方案:
# 1. 更新 pip
pip install --upgrade pip
# 2. 使用國內鏡像(中國大陸用戶)
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 3. 逐個安裝依賴
pip install -r requirements.txt --no-depsA: 訪問 PyTorch 官網 獲取適合您系統的安裝命令。
A:
# TensorFlow 2.20+ 自動檢測 GPU
pip install tensorflow
# 驗證 GPU
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"A:
# 設置執行策略
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserA:
# 使用 conda(推薦)
conda install pytorch torchvision torchaudio -c pytorch
# 某些包需要 Rosetta 2
arch -x86_64 pip install package-nameA:
# 限制並行下載
pip install -r requirements.txt --no-cache-dir
# 逐個安裝
cat requirements.txt | xargs -n 1 pip installA:
# 使用 pip-tools 管理依賴
pip install pip-tools
pip-compile requirements.in
pip-sync requirements.txt創建 verify_installation.py:
#!/usr/bin/env python
"""驗證環境安裝"""
def verify_basic():
"""驗證基礎包"""
try:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
print("✅ 基礎包安裝成功")
return True
except ImportError as e:
print(f"❌ 基礎包安裝失敗: {e}")
return False
def verify_ml():
"""驗證機器學習包"""
try:
import sklearn
import xgboost
import lightgbm
print("✅ 機器學習包安裝成功")
return True
except ImportError as e:
print(f"❌ 機器學習包安裝失敗: {e}")
return False
def verify_dl():
"""驗證深度學習包"""
try:
import torch
import tensorflow as tf
import transformers
print("✅ 深度學習包安裝成功")
print(f" PyTorch: {torch.__version__}")
print(f" TensorFlow: {tf.__version__}")
print(f" Transformers: {transformers.__version__}")
return True
except ImportError as e:
print(f"❌ 深度學習包安裝失敗: {e}")
return False
def verify_llm():
"""驗證 LLM 包"""
try:
import langchain
import chromadb
import openai
print("✅ LLM 應用包安裝成功")
return True
except ImportError as e:
print(f"❌ LLM 應用包安裝失敗: {e}")
return False
if __name__ == "__main__":
print("🔍 開始驗證環境...")
print("-" * 50)
verify_basic()
verify_ml()
verify_dl()
verify_llm()
print("-" * 50)
print("✨ 驗證完成!")執行驗證:
python verify_installation.py如果遇到問題:
祝學習愉快!🎉