ModuleNotFoundError: No module named 'triton'(ComfyUI)
修復 ComfyUI 中的 ModuleNotFoundError: No module named 'triton'——區分無害的 comfy_kitchen 日誌與阻塞性的 SageAttention、WanVideoWrapper 或加速棧故障。
如果你搜尋的是 ModuleNotFoundError: No module named 'triton'、comfyui no module named triton,或者完整的 Found comfy_kitchen backend triton: {'available': False, ...} 日誌,請先判斷這究竟只是一條可選後端報告,還是會阻塞工作流的匯入錯誤。
如果 ComfyUI 仍能正常打開且普通工作流可以運行,不必理會 Triton。如果 Easy-SAM3、Trellis、WanVideoWrapper、SageAttention 或其他節點因為匯入 Triton 而失敗,請在啟動 ComfyUI 所用的同一 Python 環境中修復 Triton。在 Windows 上,請使用 triton-windows,而不是盲目執行 pip install triton。
如果你的阻塞錯誤只是 No module named 'sageattention' 且未提及 Triton,請先參閱 SageAttention 缺失。
Wonderful Launcher 在截至 2026 年 7 月 8 日的 30 天遙測數據中,triton 是缺失模組熱點中占比最大的:29 個安裝實例在 comfy_kitchen 中觸發了致命的 No module named 'triton' 錯誤,另有 13 個安裝實例在無該上下文的情況下觸發了致命的 Triton 匯入錯誤,還有 35 個安裝實例出現了可選的 comfy_kitchen Triton 能力警告。這正是本頁將"忽略警告"與"修復真正的工作流阻塞"分開討論的原因。
30 秒分診決策
如果唯一的消息是 comfy_kitchen backend triton 且 ComfyUI 能正常打開,就不必處理。如果 Easy-SAM3、Trellis、WanVideoWrapper、SageAttention 或其他工作流出現 ModuleNotFoundError: No module named 'triton' 失敗,請在啟動 ComfyUI 所用的同一 Python 環境中修復 Triton。在 Windows 上,從 triton-windows 入手,而不是盲目執行 pip install triton。
快速參考
| 你看到的内容 | 含义 | 推薦操作 |
|---|---|---|
Found comfy_kitchen backend triton: {'available': False, ...} 且 ComfyUI 能正常打開 | 可選後端不可用 | 通常可忽略 |
工作流匯入或佇列執行時出現 ModuleNotFoundError: No module named 'triton' | 某個自定義節點實際嘗試匯入 Triton | 在同一 Python 環境中修復 Triton |
SageAttention 節點出現 No module named 'triton' | SageAttention 或自定義節點需要 Triton | 在同一 Python 環境中修復 Triton |
SageAttention 或 Triton 安裝附近出現 No module named 'flash_attn' | 相鄰的注意力加速包缺失 | 在創建單獨修復路徑之前,將其視為同一加速棧的一部分 |
Windows 上 pip install triton 失敗 | 普通 triton 包路徑不適用於 Windows | 改用 triton-windows |
| 安裝了 Triton 但 ComfyUI 仍無法匯入 | 安裝到了錯誤的 Python 環境 | 使用實際啟動 ComfyUI 的 Python 環境 |
安裝後出現 tcc.exe、triton_key 或編譯器錯誤 | 版本或執行時不匹配 | 檢查 PyTorch/Triton 映射關係,必要時回滾 |
基於遙測的問題分類
近期啟動器遙測數據顯示兩種不同的 Triton 模式:
| 模式 | 公開症狀 | 處理方式 |
|---|---|---|
| 可選能力警告 | Found comfy_kitchen backend triton: {'available': False, ...} 但 ComfyUI 仍能打開 | 不要僅為消除這一行而更換包 |
| 致命匯入錯誤 | 加載或排隊工作流時出現 ModuleNotFoundError: No module named 'triton' | 在啟動 ComfyUI 的 Python 環境中修復 Triton |
| 加速棧故障 | 啟用 SageAttention 或視頻加速後出現 No module named 'triton'、triton_key、tcc.exe 或編譯器/DLL 錯誤 | 先修復 Triton,再驗證 SageAttention 或視頻節點 |
| 相鄰注意力包故障 | No module named 'flash_attn'、flash_attn.bert_padding 或 flash_attn.flash_attn_interface | 檢查工作流是否真正需要 FlashAttention;除非 Search Console 後來顯示獨立的查詢集群,否則將修復保持在 Triton/SageAttention 附近 |
如果同一啟動警告反復出現但工作流仍能運行,那只是噪音。如果某個特定自定義節點因匯入 triton 而停止運行,則需要採取行動。
如果日誌中提到 comfy_kitchen backend triton
這條精確的日誌通常是能力報告,並不總是崩潰:
Found comfy_kitchen backend triton: {'available': False, 'disabled': True, 'unavailable_reason': "ImportError: No module named 'triton'", 'capabilities': []}如果 ComfyUI 能正常打開且工作流可以運行,不必為了消除這一行而修復 Triton。如果來自 Easy-SAM3、Trellis、WanVideoWrapper、SageAttention 或其他加速密集型節點的工作流在此消息後立即失敗,則應將 Triton 視為阻塞相依鏈的一部分。
判斷邏輯很簡單:可選啟動報告意味著觀察即可;工作流匯入或佇列執行時失敗意味著需要在同一 Python 環境中修復。
日誌的樣式
你可能會在啟動時看到這樣一行:
Found comfy_kitchen backend triton: {'available': False, 'disabled': True, 'unavailable_reason': "ImportError: No module named 'triton'", 'capabilities': []}或者工作流可能會以如下方式失敗:
ModuleNotFoundError: No module named 'triton'啟動行通常只是能力報告。工作流失敗則不同:某個節點實際嘗試匯入 triton 並停止了運行。
Triton 在 ComfyUI 中的作用
Triton 是一種 GPU 程式語言和編譯器,被 PyTorch 編譯器路徑、SageAttention 以及一些較新的加速後端等專案所使用。
ComfyUI 進行普通圖像生成時不需要 Triton。啟用 CUDA 的 PyTorch 無需 Triton 即可運行正常工作流。
Triton 在以下情況下才重要:
- 使用 SageAttention 或封裝了 SageAttention 的節點
- 使用
torch.compile或啟用了編譯內核的自定義節點 - 使用報告 Triton 能力的
comfy_kitchen加速後端 - 明確要求基於 Triton 加速的視頻或大模型工作流
如果你不使用上述任何一項,修復 Triton 可能會增加風險而不解決真正的問題。
為什麼 SageAttention 和 Triton 相互關聯
在 ComfyUI 支持日誌中,SageAttention 和 Triton 經常出現在同一修復路徑上。
SageAttention 是用戶嘗試啟用的加速功能。Triton 是 SageAttention 或相鄰加速代碼可能需要用於編譯內核的底層包之一。這意味著 SageAttention 安裝可能以三種看起來不同的方式失敗:
| 用戶目標 | 出現的錯誤 | 首先使用的頁面 |
|---|---|---|
| 啟用 SageAttention | No module named 'sageattention' | SageAttention 缺失 |
| 在 Windows 上運行 SageAttention | No module named 'triton' | 本 Triton 指南 |
| 安裝加速包後運行視頻工作流 | tcc.exe、triton_key、DLL 或編譯器錯誤 | 先看本 Triton 指南,再看 SageAttention 指南 |
安全的操作順序是:確認 ComfyUI 仍能啟動,確認確切的 Python 環境,僅在失敗的 SageAttention 工作流確實需要 Triton 時才修復它,然後在 Triton 正常工作後驗證 SageAttention 匯入。
第一步:判斷是否為致命錯誤
首先檢查 ComfyUI 是否到達正常的就緒行:
To see the GUI go to: http://127.0.0.1:8188如果瀏覽器 UI 能打開且一個簡單的默認工作流可以運行,則將 Triton 行視為可選項。在調試正常運行的環境時,不要安裝加速包。
如果特定工作流失敗,請閱讀堆疊跟蹤並確認是哪個包請求了 Triton。許多真實報告來自 SageAttention 節點、Wan/LTX 視頻工作流或優化節點。
第二步:檢查 ComfyUI 實際使用的 Python
大多數失敗的修復是因為 pip 安裝到了系統 Python,而 ComfyUI 使用的是免安裝版內建 Python 或虛擬環境。
對於 GitHub Windows 免安裝版,請從解壓縮後的根目錄(包含 run_*.bat 文件、python_embeded 和 ComfyUI 的資料夾)運行檢查:
.\python_embeded\python.exe -s -c "import sys; print(sys.executable); print(sys.version)"
.\python_embeded\python.exe -s -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"
.\python_embeded\python.exe -s -m pip show triton triton-windows對於手動安裝,激活你用於啟動 ComfyUI 的 venv:
python -c "import sys; print(sys.executable); print(sys.version)"
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"
python -m pip show triton triton-windows如果 torch.cuda.is_available() 返回 False,請先修復 PyTorch/CUDA。Triton 不會將純 CPU PyTorch 安裝變成可用的 CUDA 環境。
對於 ComfyUI Desktop 或其他託管啟動器,請使用應用的終端或環境控制。不要假設 GitHub 免安裝版的 python_embeded 路徑在 Desktop 安裝中也存在。
第三步:在 Windows 上不要使用普通 triton 包作為修復方案
對於 Windows ComfyUI,實用的包是 triton-windows,而不是盲目執行 pip install triton。
如果你已經安裝了舊版或錯誤的 triton 包,請從同一 Python 環境中將其卸載:
.\python_embeded\python.exe -s -m pip uninstall -y triton然後安裝 triton-windows:
.\python_embeded\python.exe -s -m pip install -U "triton-windows<3.7"對於手動 venv:
python -m pip uninstall -y triton
python -m pip install -U "triton-windows<3.7"版本上限是有意為之的,它可以避免在你的 PyTorch 棧尚未準備好之前意外拉取未來的 Triton 次版本。
第四步:匹配 PyTorch 和 Triton 版本
triton-windows 跟蹤 Triton 次版本,每個 PyTorch 次版本都預期與匹配的 Triton 次版本協同工作。
如有疑問,請使用上遊 triton-windows 兼容性表。以下是實用參考:
| PyTorch | 預期 Triton 次版本 |
|---|---|
| 2.6 | 3.2 |
| 2.7 | 3.3 |
| 2.8 | 3.4 |
| 2.9 | 3.5 |
| 2.10 或 2.11 | 3.6 |
對於使用 Python 3.12 或 3.13 的當前 ComfyUI 免安裝版或桌面環境,请先檢查已安裝的 PyTorch,然後選擇 Triton 範圍。triton-windows PyPI 包提供了適用於近期 CPython 版本的 Windows wheel,但僅靠 Python 版本是不夠的,PyTorch、CUDA、GPU 以及需要 Triton 的包也都非常重要。
第五步:免安裝版 Python 可能需要 include 和 libs
某些 ComfyUI 免安裝版使用內建 Python。triton-windows 說明中指出了一個特殊的內建 Python 要求:Python 頭文件和庫可能需要存在於內建 python.exe 旁邊。
重要的細節是資料夾名稱:
includelibs
不要將 libs 與 Lib 混淆。Lib 是正常的 Python 庫資料夾,不應為此修復而修改。
如果 Triton 能匯入但編譯失敗,或者錯誤提到缺少 Python 頭文件或庫,請按照 triton-windows 免安裝版 Python 部分的說明,獲取與你的 Python 次版本匹配的確切 include 和 libs 文件。
第六步:重啟 ComfyUI 前先驗證
在同一 Python 環境中運行匯入測試:
.\python_embeded\python.exe -s -c "import triton; print(triton.__version__)"然後驗證 PyTorch 仍能識別 CUDA:
.\python_embeded\python.exe -s -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"如果匯入測試失敗,ComfyUI 也會失敗。在重啟伺服器之前,請先修復 Python 環境。
若要進行內核級驗證,請使用 triton-windows 倉庫中的測試腳本。普通匯入只能證明包已安裝;內核測試才能證明它可以編譯並運行 CUDA 內核。
常見失敗情況
| 錯誤 | 可能原因 | 修復方法 |
|---|---|---|
安裝後仍出現 No module named 'triton' | Python 環境錯誤 | 使用免安裝版內建 Python、啟動 venv 或應用託管終端 |
No module named 'triton.language'; 'triton' is not a package | 本地名為 triton 的文件/資料夾遮蔽了包 | 重命名該文件/資料夾 |
DLL load failed | 缺少執行時依賴或 wheel 不兼容 | 安裝 Visual C++ Redistributable 並檢查包版本 |
tcc.exe 編譯失敗 | Triton 執行時/編譯器不匹配 | 檢查 triton-windows 版本和 PyTorch 版本 |
cannot import triton_key | 包版本不匹配 | 刪除過時的 Triton 包並安裝匹配的版本範圍 |
| 安裝加速包前 ComfyUI 正常工作 | 可選包破壞了環境穩定性 | 卸載並恢復到 PyTorch attention |
不應執行的操作
- 不要將
triton安裝到系統 Python 並期望 ComfyUI 免安裝版能看到它。 - 不要僅因為啟動能力行提到 Triton 就去安裝它。
- 不要混用來自不同指南的隨機 SageAttention、PyTorch、CUDA 和 Triton wheel。
- 除非你確實將 ComfyUI 安裝在受保護的系統路徑中,否則不要以管理員身份運行包修復操作。
- 當說明書寫的是
libs時,不要去修改python_embeded\Lib。
何時跳過 Triton
在以下情況下跳過修復:
- ComfyUI 能正常打開且工作流可以運行
- 你使用的是純 CPU PyTorch
- 你使用的是 AMD 或 Intel 路徑,而失敗的節點是為 NVIDIA CUDA 編寫的
- 真正的失敗原因是缺少自定義節點、模型文件或 Hugging Face 下載
- 你無法確認哪個工作流節點實際需要 Triton
如果多個包同時失敗,請使用 ComfyUI 常見問題 或 如何修復 ComfyUI 插件匯入失敗錯誤。
Wonderful Launcher 如何提供幫助
當環境變得難以分析時,Wonderful Launcher 會很有用:
- 它將每個安裝的 ComfyUI 包分隔開來
- 它使精確的啟動日誌更易於收集
- 它有助於在進行風險較高的修復前保存模型和工作流
- 它提供了比每次可選後端警告後重新安裝 ComfyUI 更安全的路徑
如果 Triton 只是一個警告且 ComfyUI 能正常運行,你可能不需要進行修復。如果 Triton 與 SageAttention、PyTorch/CUDA、自定義節點或反復出現的啟動失敗一起出現,請從日誌入手,逐一修復每條相依路徑。
常見問題
comfy_kitchen backend triton 是 ComfyUI 的致命錯誤嗎?
不一定。如果 ComfyUI 能正常打開且工作流可以運行,它通常只是一條可選的後端能力報告。只有當工作流或自定義節點因嘗試匯入 Triton 而失敗時,才將其視為致命錯誤。
在 Windows 上應該運行 pip install triton 嗎?
通常不應該。對於 Windows ComfyUI 修復,請使用 triton-windows 路徑並安裝到啟動 ComfyUI 的確切 Python 環境中。普通的 pip install triton 是一種常見的錯誤環境或不受支持的包修復方式。
為什麼 Easy-SAM3、Trellis 或 WanVideoWrapper 會提到 Triton?
這些工作流可能使用了加速密集型自定義節點。Triton 在相依鏈中的位置可能低於可見節點,因此即使普通的 ComfyUI 圖像生成仍然正常,工作流也可能失敗。
相關指南
- ComfyUI No Module Named 'sageattention':忽略還是修復?
- 修復 ComfyUI 中的 No module named 錯誤
- ComfyUI 依賴衝突
- ComfyUI Torch Not Compiled With CUDA Enabled
- GPU 兼容性
- ComfyUI 常見問題
來源參考
先按上面的步驟定位根因。還卡住時,可以下載 Wonderful Launcher 檢查目前機器;啟動器原生修復、任務日誌和執行階段檢查會集中在一起。credits 只用於圖片生成和按量工具。
下載 Wonderful Launcher查看 credits 方案這篇文件解決了你的問題嗎?
你的回饋會幫助我們優先補強真實 ComfyUI 排障文件。