Skip to content

Instantly share code, notes, and snippets.

@nczz
Created August 7, 2026 02:08
Show Gist options
  • Select an option

  • Save nczz/94e62110ec183a49909c054f61ba10a4 to your computer and use it in GitHub Desktop.

Select an option

Save nczz/94e62110ec183a49909c054f61ba10a4 to your computer and use it in GitHub Desktop.
Oh My Pi (omp) Windows 安裝 SOP — 避免 native addon 載入失敗等踩雷

Oh My Pi (omp) Windows 安裝 SOP

避免踩雷的正確安裝順序。直接跑 irm https://omp.sh/install.ps1 | iex 會因為缺少前置依賴而失敗。

環境需求

  • Windows 10/11(x64)
  • PowerShell 5.1+ 或 PowerShell 7+(建議 7)
  • 系統管理員權限(安裝 VC++ Runtime 時需要)

已知踩雷點

問題 症狀 原因
Native addon 載入失敗 Failed to load pi_natives native addon for win32-x64 缺少 Visual C++ Redistributable
MCP/工具無法執行 各種 node 相關錯誤 缺少 Node.js
SSH 遠端安裝失敗 winget 卡住不動 缺少 --accept-source-agreements flag

安裝步驟(依序執行)

Step 1:安裝 Visual C++ Redistributable

omp 的 Rust native addon(pi_natives.win32-x64-baseline.node)依賴 vcruntime140.dll

# 檢查是否已安裝
Test-Path "C:\Windows\System32\vcruntime140.dll"

# 若為 False,安裝:
winget install Microsoft.VCRedist.2015+.x64 --accept-source-agreements --accept-package-agreements

Step 2:安裝 Node.js LTS

omp 的部分工具(MCP server、npm 套件整合)需要 Node.js 環境。

# 安裝 Node.js LTS
winget install OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements

# 驗證(新開 PowerShell 視窗後)
node --version
npm --version

Step 3:安裝 Git for Windows(建議)

omp 需要 bash shell 來執行 shell snapshots 和互動式終端。沒裝的話會用內建 shell,功能受限。

# 安裝 Git(含 bash)
winget install Git.Git --accept-source-agreements --accept-package-agreements

# 驗證
git --version

Step 4:安裝 omp

前置依賴都到位後,安裝 omp 本體:

# 官方安裝腳本
irm https://omp.sh/install.ps1 | iex

安裝完成後驗證:

omp --version

Step 5:設定 API Key

# 方法 A:設定環境變數(永久)
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-xxx", "User")
#
[System.Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "sk-xxx", "User")

# 方法 B:互動式登入(開啟 omp 後)
omp
# 進入後輸入 /login

Step 6:驗證完整安裝

# 所有前置依賴
Test-Path "C:\Windows\System32\vcruntime140.dll"   # True
node --version                                      # v24.x
git --version                                       # git version 2.x
omp --version                                       # omp/17.x

# 功能測試
omp --print "say hello"

一鍵腳本(全自動)

將以下存為 install-omp.ps1,以系統管理員身分執行:

#Requires -RunAsAdministrator
Write-Host "=== [1/4] Installing Visual C++ Redistributable ===" -ForegroundColor Cyan
winget install Microsoft.VCRedist.2015+.x64 --accept-source-agreements --accept-package-agreements

Write-Host "=== [2/4] Installing Node.js LTS ===" -ForegroundColor Cyan
winget install OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements

Write-Host "=== [3/4] Installing Git for Windows ===" -ForegroundColor Cyan
winget install Git.Git --accept-source-agreements --accept-package-agreements

Write-Host "=== [4/4] Installing Oh My Pi ===" -ForegroundColor Cyan
irm https://omp.sh/install.ps1 | iex

Write-Host "`n=== Done! ===" -ForegroundColor Green
Write-Host "Open a NEW PowerShell window, then run: omp --version" -ForegroundColor Yellow
Write-Host "Set API key: [System.Environment]::SetEnvironmentVariable('ANTHROPIC_API_KEY', 'your-key', 'User')" -ForegroundColor Yellow

遠端安裝(透過 SSH)

若要透過 SSH 在遠端 Windows 機器上安裝,注意:

  1. 確保 OpenSSH Server 已啟用且 DefaultShell 設為 PowerShell
  2. 所有 winget 指令必須加 --accept-source-agreements --accept-package-agreements(非互動式環境不會跳確認)
  3. 安裝後 PATH 更新可能需要重新建立 SSH 連線才會生效
# 設定 PowerShell 7 為 SSH 預設 shell
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force
Restart-Service sshd

Troubleshooting

Failed to load pi_natives native addon

# 1. 確認 VC++ Runtime 存在
Test-Path "C:\Windows\System32\vcruntime140.dll"

# 2. 若存在但仍失敗,刪除 natives 快取重裝
Remove-Item "$env:USERPROFILE\.omp\natives" -Recurse -Force
omp --version  # 會自動重新提取 native addon

omp 指令找不到

# 確認安裝路徑在 PATH 中
$env:PATH -split ";" | Where-Object { $_ -match "omp" }

# 手動加入(當次生效)
$env:PATH += ";$env:LOCALAPPDATA\omp"

# 永久加入
[System.Environment]::SetEnvironmentVariable("PATH", $env:PATH + ";$env:LOCALAPPDATA\omp", "User")

Node.js 安裝後找不到

新開一個 PowerShell 視窗(PATH 在安裝後更新,舊視窗不會自動刷新)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment