{
  "id": "python/pip-target-not-in-path",
  "signature": "ImportError: No module named 'requests' after pip install --target ./lib requests",
  "signature_zh": "ImportError：pip install --target ./lib requests 后找不到名为 'requests' 的模块",
  "regex": "ImportError:\\ No\\ module\\ named\\ 'requests'\\ after\\ pip\\ install\\ \\-\\-target\\ \\./lib\\ requests",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "pip install --target installs into the given directory but does not add it to sys.path. The interpreter cannot find the package unless PYTHONPATH or sys.path is updated.",
  "root_cause_type": "generic",
  "root_cause_zh": "pip install --target 将包安装到指定目录，但不会将其添加到 sys.path。除非更新 PYTHONPATH 或 sys.path，否则解释器找不到该包。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Reinstalling does not change sys.path.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "pip still installs to the active environment's site-packages, not the cwd.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "export PYTHONPATH=$PWD/lib:$PYTHONPATH && python -c 'import requests'",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "import sys, os; sys.path.insert(0, os.path.abspath('./lib')); import requests",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "echo $(pwd)/lib > $(python -c 'import site; print(site.getsitepackages()[0])')/mylib.pth",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}