{
  "id": "python/pip-target-dir-missing-pth",
  "signature": "ModuleNotFoundError: No module named 'package' after pip install --target ./lib package",
  "signature_zh": "在 pip install --target ./lib package 之后出现 ModuleNotFoundError：没有名为 'package' 的模块",
  "regex": "ModuleNotFoundError:\\ No\\ module\\ named\\ 'package'\\ after\\ pip\\ install\\ \\-\\-target\\ \\./lib\\ package",
  "domain": "python",
  "category": "install_error",
  "subcategory": null,
  "root_cause": "pip install --target installs into the specified directory but does not add it to sys.path, so Python cannot import the package.",
  "root_cause_type": "generic",
  "root_cause_zh": "pip install --target 将包安装到指定目录，但不会将该目录加入 sys.path，因此 Python 无法导入该包。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Upgrade does not modify sys.path; the import still fails.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Works interactively but is not persisted to the deployed environment, causing the same error in CI/production.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "--no-deps does not affect sys.path registration.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Set PYTHONPATH: export PYTHONPATH=$PWD/lib:$PYTHONPATH",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Add a .pth file in site-packages pointing to the target: echo \"/abs/path/to/lib\" > $(python -c 'import site; print(site.getsitepackages()[0])')/custom.pth",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "At runtime: import sys; sys.path.insert(0, '/abs/path/to/lib')",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-06-28",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}