fix: colab notebook — use system pip instead of venv

Colab 'python3 -m venv' fails with ensurepip error (no .venv created,
so every subsequent cell hit 'command not found'). Switch to system pip
(Colab standard) and run the API server via nohup background with log
fallback diagnostics.
This commit is contained in:
2026-08-12 16:55:21 +09:00
parent 0d90845ac6
commit f385734630
2 changed files with 19 additions and 27 deletions
+3 -3
View File
@@ -59,7 +59,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "# 3) venv + 설치 (GPU 추론은 engine+api만으로 충분 — Colab T4에 CUDA 런타임 내장)\n!python3 -m venv .venv\n!source .venv/bin/activate && pip install -q --upgrade pip\n!source .venv/bin/activate && pip install -q -e '.[engine,api]'\n!source .venv/bin/activate && pip install -q edge-tts # 샘플 음성 생성용\n\n# 이후 셀에서 activate 없이 CLI 사용 가능하게 PATH 등록\nimport os\nos.environ['PATH'] = '/content/luke_scribe/.venv/bin:' + os.environ['PATH']\nprint('설치 완료')\n!luke-scribe --help 2>&1 | head -12\n"
"source": "# 3) 설치 — Colab은 시스템 pip가 표준 (venv는 Colab에서 ensurepip 오류로 실패할 수 있음)\n!pip install -q --upgrade pip\n!pip install -q -e '.[engine,api]'\n!pip install -q edge-tts # 샘플 음성 생성용\nprint('설치 완료')\n!which luke-scribe && luke-scribe --help 2>&1 | head -8\n"
},
{
"cell_type": "markdown",
@@ -83,7 +83,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "# 5) 테스트 스위트\n!source .venv/bin/activate && python -m pytest tests/ -q 2>&1 | tail -5\n"
"source": "# 5) 테스트 스위트\n!python -m pytest tests/ -q 2>&1 | tail -5\n"
},
{
"cell_type": "markdown",
@@ -133,7 +133,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "# 10) 서버 기동 (in-proc 큐, 백그라운드)\nimport subprocess, time, os, json\nenv = dict(os.environ)\nenv['LUKESCRIBE_API_KEY_FILE'] = '/content/api_keys.json'\nenv['LUKESCRIBE_QUEUE_BACKEND'] = 'inproc'\nproc = subprocess.Popen(\n ['luke-scribe', 'serve', '--port', '8000'],\n env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,\n)\n# 기동 대기\nimport urllib.request\nfor _ in range(30):\n try:\n urllib.request.urlopen('http://localhost:8000/health', timeout=1)\n break\n except Exception:\n time.sleep(1)\nprint('서버 기동 OK')\n"
"source": "# 10) 서버 기동 (in-proc 큐, 백그라운드 — Colab에서는 %%bash --bg 또는 nohup 사용)\n!mkdir -p /content/logs\n!nohup luke-scribe serve --port 8000 > /content/logs/server.log 2>&1 &\nimport time, urllib.request\nok = False\nfor _ in range(40):\n try:\n urllib.request.urlopen('http://localhost:8000/health', timeout=1)\n ok = True\n break\n except Exception:\n time.sleep(1)\nprint('서버 기동 OK' if ok else '서버 기동 실패 — 로그:')\nif not ok:\n print(open('/content/logs/server.log').read()[-1500:])\n"
},
{
"cell_type": "code",
+16 -24
View File
@@ -93,17 +93,12 @@ def cells() -> list[dict]:
"!ffprobe -version 2>&1 | head -1\n"
),
code(
"# 3) venv + 설치 (GPU 추론은 engine+api만으로 충분 — Colab T4에 CUDA 런타임 내장)\n"
"!python3 -m venv .venv\n"
"!source .venv/bin/activate && pip install -q --upgrade pip\n"
"!source .venv/bin/activate && pip install -q -e '.[engine,api]'\n"
"!source .venv/bin/activate && pip install -q edge-tts # 샘플 음성 생성용\n"
"\n"
"# 이후 셀에서 activate 없이 CLI 사용 가능하게 PATH 등록\n"
"import os\n"
"os.environ['PATH'] = '/content/luke_scribe/.venv/bin:' + os.environ['PATH']\n"
"# 3) 설치 — Colab은 시스템 pip가 표준 (venv는 Colab에서 ensurepip 오류로 실패할 수 있음)\n"
"!pip install -q --upgrade pip\n"
"!pip install -q -e '.[engine,api]'\n"
"!pip install -q edge-tts # 샘플 음성 생성용\n"
"print('설치 완료')\n"
"!luke-scribe --help 2>&1 | head -12\n"
"!which luke-scribe && luke-scribe --help 2>&1 | head -8\n"
),
md(
"## 3) 하드웨어 감지 — T4 GPU 실제 확인\n"
@@ -118,7 +113,7 @@ def cells() -> list[dict]:
md("## 4) 단위/통합 테스트 (127개)\n\nmock 기반 테스트가 GPU 환경에서도 전부 통과하는지 확인합니다."),
code(
"# 5) 테스트 스위트\n"
"!source .venv/bin/activate && python -m pytest tests/ -q 2>&1 | tail -5\n"
"!python -m pytest tests/ -q 2>&1 | tail -5\n"
),
md(
"## 5) 실전 전사 (GPU)\n\n"
@@ -155,24 +150,21 @@ def cells() -> list[dict]:
"!luke-scribe key --create --scopes transcribe,admin --file /content/api_keys.json\n"
),
code(
"# 10) 서버 기동 (in-proc 큐, 백그라운드)\n"
"import subprocess, time, os, json\n"
"env = dict(os.environ)\n"
"env['LUKESCRIBE_API_KEY_FILE'] = '/content/api_keys.json'\n"
"env['LUKESCRIBE_QUEUE_BACKEND'] = 'inproc'\n"
"proc = subprocess.Popen(\n"
" ['luke-scribe', 'serve', '--port', '8000'],\n"
" env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,\n"
")\n"
"# 기동 대기\n"
"import urllib.request\n"
"for _ in range(30):\n"
"# 10) 서버 기동 (in-proc 큐, 백그라운드 — Colab에서는 %%bash --bg 또는 nohup 사용)\n"
"!mkdir -p /content/logs\n"
"!nohup luke-scribe serve --port 8000 > /content/logs/server.log 2>&1 &\n"
"import time, urllib.request\n"
"ok = False\n"
"for _ in range(40):\n"
" try:\n"
" urllib.request.urlopen('http://localhost:8000/health', timeout=1)\n"
" ok = True\n"
" break\n"
" except Exception:\n"
" time.sleep(1)\n"
"print('서버 기동 OK')\n"
"print('서버 기동 OK' if ok else '서버 기동 실패 — 로그:')\n"
"if not ok:\n"
" print(open('/content/logs/server.log').read()[-1500:])\n"
),
code(
"# 11) 업로드 → poll → 결과\n"