1. Windows 10/11 装 OpenClaw 到底卡在哪
OpenClaw 是一个面向机器人控制与自动化编排的开源框架,能在 Windows 上跑本地推理、串口通信和任务调度。它适合做机器人控制应用开发、自动化流程编排,以及需要本地跑模型推理的开发者。但它在 Windows 上的安装体验和 Linux 差别很大:没有 apt,没有预编译包,MSVC 工具链、CMake 生成器、Python 虚拟环境三者版本对不上就报错。我见过最多的三类失败是:CMake Error: could not find any instance of Visual Studio、cl.exe is not recognized、以及pip install -r requirements.txt
在编译 C 扩展时挂掉。
这篇按 2026 年最新版 OpenClaw 的仓库结构写,从 PowerShell 环境准备一路到config.toml
骨架和运行验证。所有命令都可以直接复制到管理员 PowerShell 里执行。如果你后面要接模型服务做推理,我会在第 2 节说明怎么把 TaoToken 的 API Key 填进配置,这样 OpenClaw 的模型调用环节不用自己搭服务。
先明确一个前提:OpenClaw 的构建依赖 MSVC 编译器,不是 MinGW,也不是 WSL。所以 Visual Studio Build Tools 是必装项,且必须勾选 C++ 生成工具工作负载。下面每一步都有验证动作,做完一步确认一步,别一口气全跑完再排错。
2. 前置准备:TaoToken 与 API Key 获取
OpenClaw 本身是本地框架,但它的模型推理层支持通过 OpenAI 兼容接口调用远端服务。如果你不想在本地跑大模型,可以用 TaoToken 作为模型服务提供方,它提供 OpenAI 兼容的/v1/chat/completions
接口,配置进 OpenClaw 后就能直接调用。
操作路径:打开官网 https://taotoken.net/?utm_source=taotoken_aicg_blog_end&utm_medium=csdn&utm_campaign=rewrite&utm_content= ,注册后在控制台创建 API Key。控制台地址是 https://taotoken.net/console?utm_source=taotoken_aicg_blog_end&utm_content=console&utm_campaign=rewrite ,API Key 管理页在 https://taotoken.net/api-keys?utm_source=taotoken_aicg_blog_end&utm_content=api-keys&utm_campaign=rewrite 。创建后复制那串sk-开头的 Key,后面写进config.toml
。
API 基础地址填https://taotoken.net/api,注意这个地址不带任何查询参数。模型名按你控制台里开通的填,比如gpt-4o或claude-3-5-sonnet
这类。如果你要长期跑编码类 Agent 任务,可以看 Coding Plan 页面 https://taotoken.net/coding-plan?utm_source=taotoken_aicg_blog_end&utm_content=coding-plan&utm_campaign=rewrite ,按用量选套餐比单次调用划算。想先验证模型通不通,用模型对话页 https://taotoken.net/chat?utm_source=taotoken_aicg_blog_end&utm_content=chat&utm_campaign=rewrite 发一条消息即可。接入文档在 https://taotoken.net/doc?utm_source=taotoken_aicg_blog_end&utm_content=doc&utm_campaign=rewrite ,Claude Code 相关配置参考 https://taotoken.net/claudecode-anthropic?utm_source=taotoken_aicg_blog_end&utm_content=claudecode-anthropic&utm_campaign=rewrite 。
注意:API Key 只显示一次,创建后立刻复制保存。写进配置文件时不要提交到 Git 仓库。
3. 可复制配置:PowerShell 环境与依赖安装
3.1 环境检测脚本
3.1 环境检测脚本
先以管理员身份打开 PowerShell,跑一遍检测。这段脚本会输出每项依赖的版本和是否达标。
# 检查 Windows 版本与架构 Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer $env:PROCESSOR_ARCHITECTURE # 检查管理员权限 ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) # 检查 PowerShell 版本(需 >= 5.1) $PSVersionTable.PSVersion # 检查 .NET Framework(Release >= 528040 表示 4.8+) Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release # 检查磁盘空间(需 >= 15GB) (Get-PSDrive C).Free / 1GB如果PROCESSOR_ARCHITECTURE返回ARM64
,当前 OpenClaw 的 MSVC 构建链不支持,需要换 x64 机器或虚拟机。磁盘空间低于 15GB 的话,Build Tools 加依赖装完会爆盘。
3.2 安装 Visual Studio Build Tools
这是最容易失败的一步。用官方 aka.ms 短链下载,然后静默安装 VCTools 工作负载。
$vsUrl = "https://aka.ms/vs/17/release/vs_BuildTools.exe" $vsPath = "$env:TEMP\vs_BuildTools.exe" Invoke-WebRequest -Uri $vsUrl -OutFile $vsPath Test-Path $vsPath Start-Process -FilePath $vsPath -ArgumentList ` "--passive", "--wait", "--norestart", "--nocache", ` "--add", "Microsoft.VisualStudio.Workload.VCTools", ` "--includeRecommended" -Wait安装完成后验证编译器。注意cl和link不在系统 PATH 里,必须通过vcvars64.bat
加载环境:
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" cl linkcl输出Microsoft (R) C/C++ Optimizing Compiler Version 19.xx就对了。如果提示找不到文件,说明 Build Tools 装到了别的版本目录,用Get-ChildItem "${env:ProgramFiles(x86)}\Microsoft Visual Studio"
看一下实际路径。
3.3 安装 Python、CMake、Git
三个都用静默参数装,装完刷新环境变量。
# Python 3.11 $pyUrl = "https://www.python.org/ftp/python/3.11.8/python-3.11.8-amd64.exe" $pyPath = "$env:TEMP\python-3.11.8-amd64.exe" Invoke-WebRequest -Uri $pyUrl -OutFile $pyPath Start-Process -FilePath $pyPath -ArgumentList ` "/passive", "InstallAllUsers=1", "PrependPath=1", "Include_test=0" -Wait # CMake $cmUrl = "https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-windows-x86_64.msi" $cmPath = "$env:TEMP\cmake-3.28.0-windows-x86_64.msi" Invoke-WebRequest -Uri $cmUrl -OutFile $cmPath Start-Process msiexec -ArgumentList "/i", $cmPath, "/passive", "ADD_CMAKE_TO_PATH=System" -Wait # Git $gitUrl = "https://github.com/git-for-windows/git/releases/download/v2.43.0.windows.1/Git-2.43.0-64-bit.exe" $gitPath = "$env:TEMP\Git-2.43.0-64-bit.exe" Invoke-WebRequest -Uri $gitUrl -OutFile $gitPath Start-Process -FilePath $gitPath -ArgumentList ` "/VERYSILENT", "/NORESTART", "/NOCANCEL", "/SP-", "/SUPPRESSMSGBOXES" -Wait # 刷新 PATH $env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path','User') # 验证 python --version cmake --version git --version三个版本号都打出来才算过。如果python
还是找不到,关掉 PowerShell 重开一个,环境变量在旧会话里不生效。
3.4 克隆仓库与虚拟环境
$workDir = "C:\OpenClaw" New-Item -ItemType Directory -Path $workDir -Force | Out-Null Set-Location $workDir git clone https://github.com/openclaw/openclaw.git Set-Location openclaw python -m venv venv & venv\Scripts\Activate.ps1 python -m pip install --upgrade pip pip install -r requirements.txt
$workDir = "C:\OpenClaw" New-Item -ItemType Directory -Path $workDir -Force | Out-Null Set-Location $workDir git clone https://github.com/openclaw/openclaw.git Set-Location openclaw python -m venv venv & venv\Scripts\Activate.ps1 python -m pip install --upgrade pip pip install -r requirements.txt如果Activate.ps1报执行策略错误,先跑Set-ExecutionPolicy -Scope CurrentUser RemoteSigned再激活。requirements.txt里如果有需要编译的包,确保当前会话已经跑过vcvars64.bat,否则会报Microsoft Visual C++ 14.0 or greater is required
。
3.5 CMake 构建
New-Item -ItemType Directory -Path build -Force | Out-Null Set-Location build cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release cmake --build . --config Release --parallel cmake --install . --config Release --prefix "C:\Program Files\OpenClaw"
New-Item -ItemType Directory -Path build -Force | Out-Null Set-Location build cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release cmake --build . --config Release --parallel cmake --install . --config Release --prefix "C:\Program Files\OpenClaw"-G参数必须和已装的 VS 版本匹配。装的是 Build Tools 2022 就用Visual Studio 17 2022,写错生成器名会直接报找不到。--parallel不加参数表示用全部核心,内存小于 8GB 的话建议改成--parallel 2
,否则链接阶段容易 OOM。
3.6 config.toml 骨架
安装完成后创建配置目录和文件。OpenClaw 读的是%APPDATA%\OpenClaw\config.toml
。
$configDir = "$env:APPDATA\OpenClaw" New-Item -ItemType Directory -Path $configDir -Force | Out-Null New-Item -ItemType File -Path "$configDir\config.toml" -Force | Out-Null notepad "$configDir\config.toml"把下面这段骨架粘进去,把api_key
换成你在 TaoToken 控制台创建的那串:
[server] host = "127.0.0.1" port = 8080 log_level = "info" [model] provider = "openai-compatible" base_url = "https://taotoken.net/api" api_key = "sk-你的Key" model_name = "gpt-4o" timeout_seconds = 60 max_retries = 3 [storage] data_dir = "C:\\ProgramData\\OpenClaw\\data" cache_size_mb = 512 [runtime] max_workers = 4 enable_gpu = falsebase_url结尾不要加/v1,OpenClaw 内部会自己拼路径。enable_gpu在没装 CUDA 的机器上保持false,否则启动时报找不到cudart64_*.dll
。
4. 验证请求与成功结果
4.1 验证安装
$env:OPENCLAW_HOME = "C:\Program Files\OpenClaw" $env:Path += ";$env:OPENCLAW_HOME\bin" openclaw --version openclaw config --validate openclaw config --show
4.1 验证安装
$env:OPENCLAW_HOME = "C:\Program Files\OpenClaw" $env:Path += ";$env:OPENCLAW_HOME\bin" openclaw --version openclaw config --validate openclaw config --show--version输出类似OpenClaw 0.9.x (build 20260115)。--validate返回Configuration is valid
说明 TOML 语法和必填项都没问题。
4.2 验证模型接口连通
先用一条 curl 确认 TaoToken 的接口能通,排除网络和 Key 的问题:
$headers = @{ "Authorization" = "Bearer sk-你的Key" "Content-Type" = "application/json" } $body = @{ model = "gpt-4o" messages = @(@{ role = "user"; content = "ping" }) } | ConvertTo-Json -Depth 5 Invoke-RestMethod -Uri "https://taotoken.net/api/v1/chat/completions" ` -Method Post -Headers $headers -Body $body返回 JSON 里choices[0].message.content有内容就说明 Key 和网络都正常。如果返回 401,检查 Key 有没有复制全;返回 404,检查base_url是不是写成了带/v1
的。
4.3 启动 OpenClaw 并跑测试
openclaw start openclaw status openclaw test --unit openclaw logs --tail 50
openclaw start openclaw status openclaw test --unit openclaw logs --tail 50status显示running且端口 8080 在监听,就说明服务起来了。test --unit全绿表示核心模块加载正常。logs里如果出现model provider connected
,说明模型层也接上了。
5. 本篇常见错排查
5.1 CMake 找不到 Visual Studio
5.1 CMake 找不到 Visual Studio
报错原文:CMake Error at CMakeLists.txt: could not find any instance of Visual Studio
。
原因是 Build Tools 没装 VCTools 工作负载,或者装了但 CMake 版本太老识别不了 VS 2022。先确认cl能跑,再确认cmake --version大于 3.15。两个都满足还报错,删掉build
目录重新生成:
Set-Location .. Remove-Item build -Recurse -Force New-Item -ItemType Directory -Path build -Force | Out-Null Set-Location build cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release5.2 pip 安装依赖时编译失败
报错原文:error: Microsoft Visual C++ 14.0 or greater is required
。
这是因为当前 PowerShell 会话没有加载 MSVC 环境变量。先跑vcvars64.bat
,再激活虚拟环境,再装依赖:
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" & venv\Scripts\Activate.ps1 pip install -r requirements.txt顺序不能反,vcvars64.bat必须在激活 venv 之前或之后都行,但必须在pip install
之前。
5.3 编译阶段链接报错 LNK1104
报错原文:LNK1104: cannot open file 'python311.lib'
。
这是 Python 开发库没装。用官方安装器重跑一遍,勾选Include_lib或者手动把C:\Program Files\Python311\libs加到 CMake 的-DPYTHON_LIBRARY
参数里:
cmake .. -G "Visual Studio 17 2022" -A x64 ` -DCMAKE_BUILD_TYPE=Release ` -DPYTHON_LIBRARY="C:\Program Files\Python311\libs\python311.lib" ` -DPYTHON_INCLUDE_DIR="C:\Program Files\Python311\include"5.4 启动时报端口占用
报错原文:OSError: [WinError 10048] 通常每个套接字地址只允许使用一次
。
8080 被别的进程占了。查一下是谁:
Get-NetTCPConnection -LocalPort 8080 | Select-Object OwningProcess Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess要么停掉那个进程,要么改config.toml里的port为 8081 或其他空闲端口,然后openclaw config --reload
。
5.5 模型调用返回 401 或超时
401 基本都是 Key 的问题:复制时带了空格、Key 被撤销、或者base_url写错。超时的话把timeout_seconds从 60 调到 120,max_retries调到 5。如果公司网络有出口限制,确认taotoken.net
能正常解析。
6. 装完之后怎么接模型服务
OpenClaw 装好只是第一步,真正跑起来要靠模型层。上面config.toml里的[model]段就是接 TaoToken 的地方,改完配置用openclaw config --reload
热加载,不用重启服务。
如果你要验证不同模型在 OpenClaw 里的表现,直接去模型对话页 https://taotoken.net/chat?utm_source=taotoken_aicg_blog_end&utm_content=chat&utm_campaign=rewrite 试一条,确认模型名和返回格式对得上再写进配置。长期跑编码类 Agent 任务的话,Coding Plan https://taotoken.net/coding-plan?utm_source=taotoken_aicg_blog_end&utm_content=coding-plan&utm_campaign=rewrite 按用量计费比单次调用省。API Key 管理和新建都在 https://taotoken.net/api-keys?utm_source=taotoken_aicg_blog_end&utm_content=api-keys&utm_campaign=rewrite ,接入细节看文档 https://taotoken.net/doc?utm_source=taotoken_aicg_blog_end&utm_content=doc&utm_campaign=rewrite 。
最后提醒一个实操细节:config.toml里的路径用双反斜杠\\或者正斜杠/,单反斜杠在 TOML 里是转义字符,C:\ProgramData会被解析成C:ProgramData
,启动时报目录不存在。这个坑我踩过,排查了半小时才发现是转义问题。