Skip to content

Cannot debug Python modules via launch.vs.json #7675

Closed

Description

This issue has been moved from a ticket on Developer Community.


Visual Studio provides a way to debug Python programs, but fails to launch modules properly, so relative imports are failing. Consider this script (see attached project for a full example):

import sys

from ..util.abc import ABC      # requires -m mymod.app.app to run

def main() -> int:
    abc = ABC("ABC")

    print(f"abc: {str(abc)} args: {sys.argv}")

    return 0

if __name__ == "__main__":
    sys.exit(main())

This module can be debugged via VS Code using this launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "mymod.app.app",
            "justMyCode": true
        }
    ]
}

However, Visual Studio provides no way to specify module debugging in launch.vs.json, so from ..util.abc import ABC always fails to import another module from the same package because the import uses a relative path, which requires app to have a top-level Python module.

Using "interpreterArguments": "-m mymod.app.app" just runs the module and fails to attach a debugger to app.py because all debugpy arguments are added after -m, so they are ignored.

module-test.zip


Original Comments

Feedback Bot on 6/29/2023, 06:19 PM:

(private comment, text removed)


Original Solutions

(no solutions)

Activity

  1. StellaHuang95 commented on Jul 12, 2023

    @StellaHuang95
    Contributor

    Thanks for the issue. Moving this issue to discussion as an enhancement request for comments and upvotes.

  2. locked and limited conversation to collaborators on Jul 12, 2023
  3. converted this issue into a discussion #7676 on Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions