Showing
1 changed file
with
157 additions
and
0 deletions
| ... | @@ -33,6 +33,8 @@ git clone <仓库地址> langgraph | ... | @@ -33,6 +33,8 @@ git clone <仓库地址> langgraph |
| 33 | 33 | ||
| 34 | ### 2. 安装依赖 | 34 | ### 2. 安装依赖 |
| 35 | 35 | ||
| 36 | +#### 标准安装方式(如果系统 pip 正常) | ||
| 37 | + | ||
| 36 | ```bash | 38 | ```bash |
| 37 | cd ~/langgraph | 39 | cd ~/langgraph |
| 38 | python3 -m venv venv | 40 | python3 -m venv venv |
| ... | @@ -42,6 +44,161 @@ pip install -r requirements.txt | ... | @@ -42,6 +44,161 @@ pip install -r requirements.txt |
| 42 | pip install uvicorn python-dotenv | 44 | pip install uvicorn python-dotenv |
| 43 | ``` | 45 | ``` |
| 44 | 46 | ||
| 47 | +#### 故障排除:如果虚拟环境创建失败 | ||
| 48 | + | ||
| 49 | +**问题1:`ensurepip` 失败或 pip 损坏** | ||
| 50 | + | ||
| 51 | +如果遇到以下错误: | ||
| 52 | +``` | ||
| 53 | +Error: Command '['.../venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1. | ||
| 54 | +``` | ||
| 55 | + | ||
| 56 | +**解决方案:使用 --without-pip 创建虚拟环境** | ||
| 57 | + | ||
| 58 | +```bash | ||
| 59 | +cd ~/langgraph | ||
| 60 | + | ||
| 61 | +# 1. 检查系统 pip 是否可用 | ||
| 62 | +python3 -m pip --version | ||
| 63 | + | ||
| 64 | +# 2. 如果系统 pip 损坏,先修复系统 pip | ||
| 65 | +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | ||
| 66 | +python3 get-pip.py | ||
| 67 | +rm get-pip.py | ||
| 68 | + | ||
| 69 | +# 3. 使用 --without-pip 创建虚拟环境 | ||
| 70 | +python3 -m venv venv --without-pip | ||
| 71 | + | ||
| 72 | +# 4. 激活虚拟环境 | ||
| 73 | +source venv/bin/activate | ||
| 74 | + | ||
| 75 | +# 5. 使用系统 pip 安装 pip、setuptools、wheel 到虚拟环境 | ||
| 76 | +# 注意:将 python3.12 替换为你的实际 Python 版本(如 python3.10) | ||
| 77 | +python3 -m pip install --target venv/lib/python3.12/site-packages pip setuptools wheel | ||
| 78 | + | ||
| 79 | +# 6. 验证 pip 是否可用 | ||
| 80 | +python3 -m pip --version | ||
| 81 | + | ||
| 82 | +# 7. 安装项目依赖(使用 python3 -m pip 更可靠) | ||
| 83 | +python3 -m pip install -r requirements.txt | ||
| 84 | +python3 -m pip install uvicorn python-dotenv | ||
| 85 | +``` | ||
| 86 | + | ||
| 87 | +**问题2:系统 pip 损坏(ModuleNotFoundError: No module named 'distutils')** | ||
| 88 | + | ||
| 89 | +如果遇到 `distutils` 模块缺失错误: | ||
| 90 | + | ||
| 91 | +```bash | ||
| 92 | +# 1. 重新安装系统 pip | ||
| 93 | +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | ||
| 94 | +python3 get-pip.py | ||
| 95 | +rm get-pip.py | ||
| 96 | + | ||
| 97 | +# 2. 验证 | ||
| 98 | +python3 -m pip --version | ||
| 99 | + | ||
| 100 | +# 3. 然后按照"问题1"的解决方案继续 | ||
| 101 | +``` | ||
| 102 | + | ||
| 103 | +**问题3:网络问题无法下载 get-pip.py** | ||
| 104 | + | ||
| 105 | +如果无法访问 `bootstrap.pypa.io`: | ||
| 106 | + | ||
| 107 | +```bash | ||
| 108 | +# 方法1:使用国内镜像(如果可用) | ||
| 109 | +curl https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/get-pip.py -o get-pip.py | ||
| 110 | +# 注意:如果下载的是 HTML 重定向页面,需要使用方法2 | ||
| 111 | + | ||
| 112 | +# 方法2:直接使用系统 pip 安装到虚拟环境(推荐) | ||
| 113 | +cd ~/langgraph | ||
| 114 | +python3 -m venv venv --without-pip | ||
| 115 | +source venv/bin/activate | ||
| 116 | + | ||
| 117 | +# 退出虚拟环境,使用系统 pip | ||
| 118 | +deactivate | ||
| 119 | +# 注意:将 python3.12 替换为你的实际 Python 版本 | ||
| 120 | +python3 -m pip install --target venv/lib/python3.12/site-packages pip setuptools wheel | ||
| 121 | + | ||
| 122 | +# 重新激活虚拟环境 | ||
| 123 | +source venv/bin/activate | ||
| 124 | +python3 -m pip install -r requirements.txt | ||
| 125 | +python3 -m pip install uvicorn python-dotenv | ||
| 126 | +``` | ||
| 127 | + | ||
| 128 | +#### 完整安装流程(推荐,适用于所有情况) | ||
| 129 | + | ||
| 130 | +```bash | ||
| 131 | +cd ~/langgraph | ||
| 132 | + | ||
| 133 | +# 步骤1:检查 Python 和 pip | ||
| 134 | +python3 --version | ||
| 135 | +python3 -m pip --version | ||
| 136 | + | ||
| 137 | +# 步骤2:如果 pip 不可用,修复系统 pip | ||
| 138 | +if ! python3 -m pip --version > /dev/null 2>&1; then | ||
| 139 | + echo "修复系统 pip..." | ||
| 140 | + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | ||
| 141 | + python3 get-pip.py | ||
| 142 | + rm get-pip.py | ||
| 143 | +fi | ||
| 144 | + | ||
| 145 | +# 步骤3:创建虚拟环境 | ||
| 146 | +if [ -d "venv" ]; then | ||
| 147 | + echo "清理旧的虚拟环境..." | ||
| 148 | + rm -rf venv | ||
| 149 | +fi | ||
| 150 | + | ||
| 151 | +# 获取 Python 版本号(如 3.12) | ||
| 152 | +PYTHON_VERSION=$(python3 --version | awk '{print $2}' | cut -d. -f1,2) | ||
| 153 | + | ||
| 154 | +# 尝试标准方式创建 | ||
| 155 | +if ! python3 -m venv venv 2>/dev/null; then | ||
| 156 | + echo "标准方式失败,使用 --without-pip 方式..." | ||
| 157 | + python3 -m venv venv --without-pip | ||
| 158 | + | ||
| 159 | + # 使用系统 pip 安装基础包 | ||
| 160 | + python3 -m pip install --target venv/lib/python${PYTHON_VERSION}/site-packages pip setuptools wheel | ||
| 161 | +fi | ||
| 162 | + | ||
| 163 | +# 步骤4:激活虚拟环境 | ||
| 164 | +source venv/bin/activate | ||
| 165 | + | ||
| 166 | +# 步骤5:安装依赖 | ||
| 167 | +python3 -m pip install --upgrade pip | ||
| 168 | +python3 -m pip install -r requirements.txt | ||
| 169 | +python3 -m pip install uvicorn python-dotenv | ||
| 170 | + | ||
| 171 | +# 步骤6:验证安装 | ||
| 172 | +python3 -m pip list | grep -E "langgraph|uvicorn|dotenv" | ||
| 173 | + | ||
| 174 | +echo "✅ 依赖安装完成!" | ||
| 175 | +``` | ||
| 176 | + | ||
| 177 | +#### 验证安装 | ||
| 178 | + | ||
| 179 | +```bash | ||
| 180 | +# 激活虚拟环境 | ||
| 181 | +source venv/bin/activate | ||
| 182 | + | ||
| 183 | +# 检查 Python 路径(应该指向 venv) | ||
| 184 | +which python | ||
| 185 | +# 应该显示:/home/username/Test_LangGraph/venv/bin/python | ||
| 186 | + | ||
| 187 | +# 检查已安装的包 | ||
| 188 | +pip list | ||
| 189 | + | ||
| 190 | +# 测试导入关键模块 | ||
| 191 | +python -c "import langgraph; print('LangGraph OK')" | ||
| 192 | +python -c "import uvicorn; print('Uvicorn OK')" | ||
| 193 | +``` | ||
| 194 | + | ||
| 195 | +#### 注意事项 | ||
| 196 | + | ||
| 197 | +1. **Python 版本**:确保使用 Python 3.8+,推荐 Python 3.10+ | ||
| 198 | +2. **虚拟环境路径**:如果 Python 版本不是 3.12,将命令中的 `python3.12` 替换为实际版本(如 `python3.10`) | ||
| 199 | +3. **权限问题**:如果遇到权限错误,确保对项目目录有写权限 | ||
| 200 | +4. **网络问题**:如果网络不稳定,考虑使用国内镜像源或离线安装 | ||
| 201 | + | ||
| 45 | ### 3. 配置环境变量 | 202 | ### 3. 配置环境变量 |
| 46 | 203 | ||
| 47 | ```bash | 204 | ```bash | ... | ... |
-
Please register or login to post a comment