{
  "id": "ros2/colcon-build-python-import-error-no-module-named-package",
  "signature": "ImportError: No module named 'my_package' when running colcon build --packages-select my_package",
  "signature_zh": "ImportError: 运行 colcon build --packages-select my_package 时找不到模块 'my_package'",
  "regex": "ImportError: No module named '.+'",
  "domain": "ros2",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "The Python package in the ROS2 workspace is missing a __init__.py file or has an incorrect package structure, causing colcon to fail to import it during build.",
  "root_cause_type": "generic",
  "root_cause_zh": "ROS2 工作空间中的 Python 包缺少 __init__.py 文件或包结构不正确，导致 colcon 在构建期间无法导入它。",
  "versions": [
    {
      "version": "ROS2 Humble",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ROS2 Iron",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "colcon-core 0.13.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "colcon-ros 0.5.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The import error is specific to the package; building all packages may mask the issue or fail elsewhere.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is due to missing __init__.py, not build artifacts; deleting build won't fix it.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "While this may install the package, it bypasses colcon's build system and may cause inconsistencies in the workspace.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Create an empty __init__.py file in the package's source directory: 'touch src/my_package/my_package/__init__.py'",
      "success_rate": 0.95,
      "how": "Create an empty __init__.py file in the package's source directory: 'touch src/my_package/my_package/__init__.py'",
      "condition": "",
      "sources": []
    },
    {
      "action": "Verify the package structure: the source directory should contain a subdirectory with the same name as the package, containing __init__.py and other modules.",
      "success_rate": 0.9,
      "how": "Verify the package structure: the source directory should contain a subdirectory with the same name as the package, containing __init__.py and other modules.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在包的源目录中创建一个空的 __init__.py 文件：'touch src/my_package/my_package/__init__.py'",
    "验证包结构：源目录应包含一个与包同名的子目录，其中包含 __init__.py 和其他模块。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-03-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}