8000 `sysconfig.get_config_var("Py_DEBUG")` is not picked up on Windows builds · Issue #133878 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cctv130 opened this issue May 11, 2025 · 12 comments
Closed

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

cctv130 opened this issue May 11, 2025 · 12 comments
Labels
OS-windows stdlib Python modules in the Lib dir topic-sysconfig type-bug An unexpected behavior, bug, or error

Comments

@cctv130
Copy link
cctv130 commented May 11, 2025

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

@StanFromIreland

This comment has been minimized.

@picnixz
Copy link
Member
picnixz commented May 11, 2025

@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.

@picnixz picnixz 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 May 11, 2025
@picnixz
Copy link
Member
picnixz commented May 11, 2025

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

@picnixz picnixz added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels May 11, 2025
@StanFromIreland
Copy link
Contributor

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.

@cctv130
Copy link
Author
cctv130 commented May 11, 2025

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

@cctv130
Copy link
Author
cctv130 commented May 11, 2025

@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.

@picnixz
Copy link
Member
picnixz commented May 11, 2025

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

@cctv130
Copy link
Author
cctv130 commented May 11, 2025

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

@picnixz
Copy link
Member
picnixz commented May 11, 2025

Changing the build configuration and how it's being built is out-of-scope of this issue and this is not some 8000 thing 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.

@XuehaiPan
Copy link
Contributor
XuehaiPan commented May 11, 2025

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.

@zooba
Copy link
Member
zooba commented May 11, 2025

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").

@cctv130
Copy link
Author
cctv130 commented May 12, 2025

thanks

@cctv130 cctv130 closed this as completed May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows stdlib Python modules in the Lib dir topic-sysconfig type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants
0