# Codex CLI 安裝教學 本文將教你如何在不同系統(Windows / macOS / Linux)環境下安裝並使用 [OpenAI Codex CLI](https://github.com/openai/codex),並解決 Windows 常見的 `python3` 找不到問題。 --- ## 1. 安裝前置環境 在安裝 Codex CLI 前,請先確保系統已具備: * **Node.js 18 以上版本**(必須安裝 npm) 前往 [Node.js 官網](https://nodejs.org/) 下載安裝 * **(可選)Python 3.8 以上版本** 某些 Codex 功能需要 Python 支援,建議安裝並加入系統 PATH --- ## 2. 安裝 Codex CLI ### macOS ```bash brew install codex ``` ### Windows / Linux ```bash npm install -g @openai/codex ``` 安裝完成後可檢查版本: ```bash codex --version ``` --- ## 3. 登入 Codex CLI 安裝完成後,可透過以下指令登入: ```bash codex login ``` 登入時會有兩種方式: 1. **Sign in with ChatGPT** — 開啟瀏覽器並使用 OpenAI 帳號登入。 2. **輸入 API Key** — 直接在終端機貼上從 [OpenAI API Keys 頁面](https://platform.openai.com/api-keys) 取得的 API Key。 選擇其中一種方式完成登入即可開始使用。 --- ## 4. 測試 Codex CLI 執行: ```bash codex help ``` 若正常顯示指令列表,代表安裝成功。 --- ## 5. Windows 專屬問題:`python3` 找不到 ### 問題原因 在 Windows 環境中,Python 安裝後的預設執行檔名稱是 `python`,但 Codex CLI 可能呼叫 `python3`,導致系統無法找到對應指令。 ### 解決方法:建立 `python3` 別名 1. 以系統管理員身份開啟 **PowerShell** 2. 查詢 Python 路徑(若 `where python` 找不到,請改用 PowerShell 指令): ```powershell where python # 或 Get-Command python | Select-Object Source ``` 3. 建立軟連結: ```bash mklink "C:\Windows\System32\python3.exe" "C:\Users\<使用者>\AppData\Local\Programs\Python\Python3x\python.exe" ``` * 第一個路徑:建立的 `python3.exe` * 第二個路徑:實際的 `python.exe` 位置 --- ## 6. 常見問題 | 問題 | 解法 | | ------------- | ----------------------------------------------------- | | `npm` 找不到 | 安裝 [Node.js](https://nodejs.org/) 並勾選 **Add to PATH** | | `python3` 找不到 | 依照 **第 5 步驟** 建立軟連結 | | 權限不足 | 在 macOS / Linux 加上 `sudo` 執行指令;Windows 以系統管理員模式開啟終端機 | --- ## 7. 參考資源 * [OpenAI Codex CLI GitHub](https://github.com/openai/codex) * [Node.js 官方網站](https://nodejs.org/) * [Windows mklink 指令教學](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) * [OpenAI API Keys 頁面](https://platform.openai.com/api-keys) --- ✅ 現在你已經能在 Windows / macOS / Linux 順利安裝並使用 Codex CLI,並可透過 ChatGPT 登入或 API Key 啟用。
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.