Skip to content

Fix hardcoded absolute paths causing FileNotFoundError on import#8

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-absolute-path-import-error
Draft

Fix hardcoded absolute paths causing FileNotFoundError on import#8
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-absolute-path-import-error

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Config files contained hardcoded absolute paths (/home/suraj/Repositories/DINOv2_3D) that don't exist on other machines, causing import_module_from_path to fail when looking for __init__.py.

Changes

  • Config files: Replaced absolute paths with relative path "." in train.yaml, predict.yaml, and dinotxt_stage.yaml

  • scripts/run.py: Added path normalization to resolve relative paths against repository root:

    project_path = Path(project_path).expanduser()
    if not project_path.is_absolute():
        repo_root = Path(__file__).resolve().parent.parent
        project_path = (repo_root / project_path).resolve()
  • utils/imports.py: Enhanced error message to guide users when __init__.py not found:

    raise FileNotFoundError(
        f"No `__init__.py` found at `{module_path}`.\n"
        f"If your config contains an absolute path like '/home/suraj/...', "
        f"please update it to use a relative path (e.g., 'project: \".\"') "
        f"or set it to your local repository root."
    )
  • scripts/utility/export_ckpt_to_nnunet.py: Added --project-path argument with same path normalization logic

Original prompt

This section details on the original issue you should resolve

<issue_title>Absolute author-specific project path in configs causes FileNotFoundError on import</issue_title>
<issue_description>Running the CLI can fail because some configs contain an absolute, author-specific project path (e.g. /home/suraj/...). The import helper is passed that path and attempts to find __init__.py there, causing a FileNotFoundError on other machines.

Environment:

  • Repo: DINOv2-3D-Med
  • OS: Windows
  • Command used:
    python -m scripts.run fit --config_file=./configs/train.yaml,./configs/models/primus.yaml,./configs/datasets/amos.yaml

Reproduction steps:

  1. From the repository run the command above.
  2. Observe traceback ending with:
    FileNotFoundError: No __init__.py in U:\home\suraj\Repositories\DINOv2_3D\__init__.py

Actual behavior:

  • import_module_from_path is passed an absolute path pointing to the original author’s home directory; that path does not exist and the import fails.

Expected behavior:

  • project should resolve to the local repository root (or a user-specified path on the current machine), not an author-specific absolute path.
  • If project is relative (e.g. "."), resolve it relative to the repo root or CWD.
  • Error messages should include the attempted path and a hint on how to fix it.

Root cause:

  • One or more config files include an absolute project path referencing the author's machine. scripts/run.py passes that value to utils/imports.import_module_from_path which expects a package directory containing __init__.py. The absolute path is invalid on other machines so the helper raises FileNotFoundError.

Proposed fixes:

  1. Update configs to avoid absolute author-specific paths (use project: "." or env/template variables).
  2. Harden scripts/run.py:
    • Normalize and resolve project (expanduser, resolve) and treat relative paths relative to repo root or script location.
    • Provide a clearer error message if __init__.py is missing (show attempted path and guidance).
  3. Search repository for and remove any remaining hardcoded /home/suraj paths.

Workaround:

  • Set project: "." in configs and run the command from the repository root, or set project to the absolute path of your local repo.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 28, 2026 21:19
… update configs

Co-authored-by: surajpaib <10467804+surajpaib@users.noreply.github.com>
…ation

Co-authored-by: surajpaib <10467804+surajpaib@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix absolute author-specific project path in configs Fix hardcoded absolute paths causing FileNotFoundError on import Jan 28, 2026
Copilot AI requested a review from surajpaib January 28, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Absolute author-specific project path in configs causes FileNotFoundError on import

2 participants