{"record":{"id":"667a774809310891","repo":"shareAI-lab/learn-claude-code","slug":"install-dependencies-first-pip-install-r-require","errorCode":null,"errorMessage":"Install dependencies first: pip install -r requirements.txt","messagePattern":"Install dependencies first: pip install -r requirements\\.txt","errorType":"exception","errorClass":"GoalError","httpStatus":null,"severity":"error","filePath":"s17_goal_loop/code.py","lineNumber":815,"sourceCode":"            return f\"Edited {path.relative_to(self.workdir)}\"\n\n        if name == \"glob\":\n            matches = [\n                match\n                for match in glob.glob(str(arguments[\"pattern\"]), root_dir=self.workdir)\n                if (self.workdir / match).resolve().is_relative_to(self.workdir)\n            ]\n            return \"\\n\".join(matches[:200]) if matches else \"(no matches)\"\n\n        raise GoalError(f\"unknown tool '{name}'\")\n\n\ndef make_live_session(workdir: Path) -> AgentSession:\n    try:\n        from anthropic import Anthropic\n        from dotenv import load_dotenv\n    except ImportError as error:\n        raise GoalError(\n            \"Install dependencies first: pip install -r requirements.txt\"\n        ) from error\n\n    load_dotenv(override=True)\n    model = os.getenv(\"MODEL_ID\")\n    if not model:\n        raise GoalError(\"MODEL_ID is required in the environment or .env\")\n    evaluator_model = (\n        os.getenv(\"GOAL_EVALUATOR_MODEL_ID\")\n        or os.getenv(\"ANTHROPIC_DEFAULT_HAIKU_MODEL\")\n        or model\n    )\n    if os.getenv(\"ANTHROPIC_BASE_URL\"):\n        os.environ.pop(\"ANTHROPIC_AUTH_TOKEN\", None)\n    client = Anthropic(base_url=os.getenv(\"ANTHROPIC_BASE_URL\"))\n    evaluator = PromptGoalEvaluator(client=client, model=evaluator_model)\n    block_cap = int(\n        os.getenv(","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/shareAI-lab/learn-claude-code/blob/985456f4adea6f4df8fbad4112245dbd97444eae/s17_goal_loop/code.py#L797-L833","documentation":"make_live_session failed to import the optional third-party packages 'anthropic' and/or 'dotenv' (s17_goal_loop/code.py:815). The live path is optional, so these dependencies are not installed with the base code; ImportError is caught and re-raised as GoalError telling you to install requirements.txt.","triggerScenarios":"Calling make_live_session(path) in an environment where 'pip install -r requirements.txt' (which provides anthropic and python-dotenv) has not been run, or where a different virtualenv/interpreter is active than the one the packages were installed into.","commonSituations":"Fresh clone, no venv set up; running under a different python (system vs venv vs poetry/uv env); IDE launching with a stale interpreter; installing with --user into a Python other than the one runs the script.","solutions":["Run pip install -r requirements.txt inside the venv/interpreter you will execute with","Verify with 'python -c \"import anthropic, dotenv\"' using the same interpreter","If using uv/poetry, run through 'uv run python ...' / 'poetry run python ...' so the project env is used"],"exampleFix":"# before\n$ python -m s17_goal_loop.code\nerror: Install dependencies first: pip install -r requirements.txt\n\n# after\n$ python -m venv .venv && source .venv/bin/activate\n$ pip install -r requirements.txt\n$ python -m s17_goal_loop.code","handlingStrategy":"validation","validationCode":"import importlib.util\nmissing = [m for m in (\"anthropic\", \"dotenv\") if importlib.util.find_spec(m) is None]\nif missing:\n    raise SystemExit(f\"install deps first: {', '.join(missing)} (pip install -r requirements.txt)\")\nsession = make_live_session(workdir)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install requirements.txt into the exact interpreter you run with (venv/uv/poetry)","Smoke-test with 'python -c \"import anthropic, dotenv\"' before the first session","Run via 'uv run'/'poetry run' so the project environment is always used"],"tags":["goal-loop","dependencies","environment","setup"],"backgroundTag":null,"analyzedSha":"985456f4adea6f4df8fbad4112245dbd97444eae","analyzedAt":"2026-08-14T22:02:26.028Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}