Skip to content

sysconfig.get_config_var("Py_DEBUG") is not picked up on Windows builds #133878

Closed

Description

@cctv130

I used the PCbuild\build.bat -e -d -p x64 command to build, but when I print PY_DEBUG, it returns None.
Image

Activity

  1. StanFromIreland commented on May 11, 2025

    @StanFromIreland
  2. picnixz commented on May 11, 2025

    @picnixz
    Member

    @zooba should a build with -d be expected to define Py_DEBUG as well? We have this

    /* _DEBUG implies Py_DEBUG */
    #ifdef _DEBUG
    #  define Py_DEBUG 1
    #endif
    

    but it appears that sysconfig can't pick this up.

  3. changed the title [-]how to properly enable and use Py_DEBUG on Windows?[/-] [+]`sysconfig.get_config_var("Py_DEBUG")` is not picked up on Windows builds[/+] on May 11, 2025
  4. picnixz commented on May 11, 2025

    @picnixz
    Member

    @cctv130 Does it work better if you're using Python 3.13 or Python 3.14?

  5. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    and removed on May 11, 2025
  6. StanFromIreland commented on May 11, 2025

    @StanFromIreland
    Member

    It should, as per the docs:

    Debug
    Used to build Python with extra debugging capabilities, equivalent
    to using ./configure --with-pydebug on UNIX. All binaries built
    using this configuration have "_d" added to their name:
    python310_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
    build and rt (run test) batch files in this directory accept a -d
    option for debug builds. If you are building Python to help with
    development of CPython, you will most likely use this configuration.

  7. cctv130 commented on May 11, 2025

    @cctv130
    Author

    @StanFromIreland
    On the Windows platform, the compilation method is different from Linux; the ./configure command is not supported on Windows.

  8. cctv130 commented on May 11, 2025

    @cctv130
    Author

    @zooba should a build with -d be expected to define Py_DEBUG as well? We have this

    /* _DEBUG implies Py_DEBUG */
    #ifdef _DEBUG
    #  define Py_DEBUG 1
    #endif
    

    but it appears that sysconfig can't pick this up.

    If that's the case, then the _DEBUG flag must be added to the MSVC compiler.

  9. picnixz commented on May 11, 2025

    @picnixz
    Member

    _DEBUG is already MSVC-specific; I think it's more a sysconfig issue

  10. cctv130 commented on May 11, 2025

    @cctv130
    Author

    @picnixz
    If that's the case, we can use CMake configuration instead of configure to support more platforms.

  11. picnixz commented on May 11, 2025

    @picnixz
    Member

    Changing the build configuration and how it's being built is out-of-scope of this issue and this is not something we want to do now. In this case, we need to figure out why sysconfig doesn't pickup Py_DEBUG or whether it's not set.

  12. XuehaiPan commented on May 11, 2025

    @XuehaiPan
    Contributor

    I used the PCbuild\build.bat -e -d -p x64 command to build, but when I print PY_DEBUG, it returns None. Image

    The Py_DEBUG key in sysconfig.get_config_vars() on Windows was added in #131799, which first appeared in Python 3.14.0b1.

    As the screenshot shows, you are using Python 3.12.10.

  13. zooba commented on May 11, 2025

    @zooba
    Member

    Yeah sysconfig on Windows doesn't pick up anything automatically, as there's no Makefile for it to parse. XuehaiPan added some variables for 3.14 - prior to that, you needed to look for debug-only attributes (e.g. sys.gettotalrefcount is a popular choice) or Path(sys.executable).match("*_d.exe").

  14. cctv130 commented on May 12, 2025

    @cctv130
    Author

    thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsstdlibStandard Library Python modules in the Lib/ directorytopic-sysconfigtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions