安装过程
### 第 1 步:把“安装脚本”贴进去修改笔记本设置为T4,保存。然后连接。
在 Colab 页面中间那个灰色的长条框(单元格)里,把下面这段代码全部覆盖粘贴进去。这段代码会自动把软件装进你那 2TB 的硬盘里,这样以后你存几百个美女模型都不会爆。
# ========================================================
# 2TB 硬盘版 ComfyUI 一键安装脚本
# ========================================================
from google.colab import drive
import os
# 1. 挂载 2TB 谷歌硬盘 (会弹出窗口问你是否允许,选“是”)
print("正在连接您的 2TB 硬盘...")
drive.mount('/content/drive')
# 2. 设置安装路径(在你的 2TB 硬盘根目录创建一个 My_AI 文件夹)
ai_path = "/content/drive/MyDrive/My_AI_Work"
if not os.path.exists(ai_path):
os.makedirs(ai_path)
%cd {ai_path}
# 3. 下载 ComfyUI 软件本体
if not os.path.exists(f"{ai_path}/ComfyUI"):
print("正在从 GitHub 下载软件,请稍等...")
!git clone https://github.com/comfyanonymous/ComfyUI.git
else:
print("✅ 软件已存在,跳过下载。")
# 4. 安装核心驱动和环境 (这是最耗时的,大约 3-5 分钟)
print("正在给云电脑安装显卡驱动和 Python 环境...")
%cd {ai_path}/ComfyUI
!pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
!pip install -r requirements.txt
!pip install xformers
# 5. 安装插件管理器 (有了它,你以后下载美女模型和视频插件非常容易)
%cd {ai_path}/ComfyUI/custom_nodes
if not os.path.exists("ComfyUI-Manager"):
!git clone https://github.com/ltdrdata/ComfyUI-Manager.git
print("\n🎉【第一步安装成功!】")
print("现在,请点击页面左侧的【+ 代码 (+ Code)】按钮,再开一个新的单元格,")
print("然后回复我【搞定了】,我发给你启动进入软件的地址!")第二部:
# ========================================================
# 🚀 二合一必成脚本:启动 + 自动吐链接
# ========================================================
import os, subprocess, threading, time, socket
# 1. 确认进入目录
ai_path = "/content/drive/MyDrive/My_AI_Work/ComfyUI"
%cd {ai_path}
# 2. 核心:在后台等引擎启动,然后立刻抓取网址
def get_url_thread(port):
time.sleep(10) # 给引擎一点启动时间
print("正在努力为您连接访问大门...")
p = subprocess.Popen(["cloudflared", "tunnel", "--url", f"http://127.0.0.1:{port}"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in iter(p.stderr.readline, b''):
line = line.decode()
if "trycloudflare.com" in line:
url = "https://" + line.split("https://")[1].strip()
print("\n" + "⭐"*15)
print(f"🎉 进城链接在此:\n{url}")
print("⭐"*15 + "\n")
break
# 开启找链接的后台线程
threading.Thread(target=get_url_thread, daemon=True, args=(8188,)).start()
# 3. 正式启动引擎
!python main.py --dont-print-server --highvram第三步
# 运行这个,专门治你刚才发的那个 RuntimeError 报错
!pip install torchvision==0.19.0 torch==2.4.0 --extra-index-url https://download.pytorch.org/whl/cu121修好后,怎么“一键进城”?
Python
# ========================================================
# 🚀 既然装好了,咱们用“最暴力”的方式把网址逼出来
# ========================================================
import os, time
%cd /content/drive/MyDrive/My_AI_Work/ComfyUI
# 启动本地服务(后台)
get_ipython().system_raw('python main.py --dont-print-server --highvram &')
# 强制显示网址(前台)
print("正在为你打开大门,请盯紧下方:")
!wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
!dpkg -i cloudflared-linux-amd64.deb
!cloudflared tunnel --url http://127.0.0.1:8188