{
  "id": "python/pytest-import-mismatch-module-not-found",
  "signature": "ModuleNotFoundError: No module named 'myapp'",
  "signature_zh": "ModuleNotFoundError: 没有名为 'myapp' 的模块",
  "regex": "ModuleNotFoundError:\\ No\\ module\\ named\\ 'myapp'",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "pytest is run from a directory where the project root is not on sys.path. This often happens when tests are in a subdirectory and the package is not installed, or when using src layout without proper configuration.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest 在项目根目录不在 sys.path 上的目录中运行。这通常发生在测试位于子目录且包未安装，或使用 src 布局但未正确配置时。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The current working directory may not be the project root, and this is fragile.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This makes the parent directory not importable and often breaks relative imports.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Create conftest.py in the project root (even empty). pytest adds the rootdir to sys.path when it finds conftest.py.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.98,
      "how": "Run: pip install -e .\nEnsure setup.py or pyproject.toml is present with proper package discovery.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Run: python -m pytest tests/\nThis adds the current directory to sys.path.",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}