You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An exception occurred: AttributeError module 'sys' has no attribute 'real_prefix' #923
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\common\util.py", line 1, in
# Copyright (c) Microsoft Corporation. All rights reserved.
^^^^^^^^^^^^^^^
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\common\util.py", line 16, in evaluate
return eval(expr, {}, sys.modules)
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\common\log.py", line 297, in
get_paths = lambda: util.evaluate(expr)
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\common\log.py", line 299, in report_paths
paths = get_paths()
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\common\log.py", line 328, in get_environment_description
report_paths("sys.real_prefix")
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\common\log.py", line 372, in describe_environment
info("{0}", get_environment_description(header))
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\server\api.py", line 56, in ensure_logging
log.describe_environment("Initial environment:")
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\server\cli.py", line 492, in main
api.ensure_logging()
File "C:\Users\XXX.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy_main_.py", line 71, in
cli.main()
AttributeError: module 'sys' has no attribute 'real_prefix'
Something is changing 'eval' to not work. This code works fine for me. You can try sticking this in the file you're debugging and see what happens:
importosimportsysimportinspectdefforce_str(s, encoding, errors="strict"):
"""Converts s to str, using the provided encoding. If s is already str, it is returned as is. """returns.decode(encoding, errors) ifisinstance(s, bytes) elsestr(s)
defnameof(obj, quote=False):
"""Returns the most descriptive name of a Python module, class, or function, as a Unicode string If quote=True, name is quoted with repr(). Best-effort, but guaranteed to not fail - always returns something. """try:
name=obj.__qualname__exceptException:
try:
name=obj.__name__exceptException:
# Fall back to raw repr(), and skip quoting.try:
name=repr(obj)
exceptException:
return"<unknown>"else:
quote=Falseifquote:
try:
name=repr(name)
exceptException:
passreturnforce_str(name, "utf-8", "replace")
defsrcnameof(obj):
"""Returns the most descriptive name of a Python module, class, or function, including source information (filename and linenumber), if available. Best-effort, but guaranteed to not fail - always returns something. """name=nameof(obj, quote=True)
# Get the source information if possible.try:
src_file=inspect.getsourcefile(obj)
exceptException:
passelse:
name+=f" (file {src_file!r}"try:
_, src_lineno=inspect.getsourcelines(obj)
exceptException:
passelse:
name+=f", line {src_lineno}"name+=")"returnnamedefevaluate(code, path=__file__, mode="eval"):
# Setting file path here to avoid breaking here if users have set# "break on exception raised" setting. This code can potentially run# in user process and is indistinguishable if the path is not set.# We use the path internally to skip exception inside the debugger.expr=compile(code, path, "eval")
returneval(expr, {}, sys.modules)
defswallow_exception(msg, *args, level="error", **kwargs):
print(msg.format(*args, **kwargs))
defget_environment_description(header):
importsysconfigimportsite# noqaresult= [header, "\n\n"]
defreport(s, *args, **kwargs):
result.append(s.format(*args, **kwargs))
defreport_paths(get_paths, label=None):
prefix=f" {labelorget_paths}: "expr=Noneifnotcallable(get_paths):
expr=get_pathsget_paths=lambda: evaluate(expr)
try:
paths=get_paths()
exceptAttributeError:
report("{0}<missing>\n", prefix)
returnexceptException: # pragma: no coverswallow_exception(
"Error evaluating {0}",
repr(expr) ifexprelsesrcnameof(get_paths),
level="info",
)
returnifnotisinstance(paths, (list, tuple)):
paths= [paths]
forpinsorted(paths):
report("{0}{1}", prefix, p)
ifpisnotNone:
rp=os.path.realpath(p)
ifp!=rp:
report("({0})", rp)
report("\n")
prefix=" "*len(prefix)
report("System paths:\n")
report_paths("sys.executable")
report_paths("sys.prefix")
report_paths("sys.base_prefix")
report_paths("sys.real_prefix")
report_paths("site.getsitepackages()")
report_paths("site.getusersitepackages()")
site_packages= [
pforpinsys.pathifos.path.exists(p) andos.path.basename(p) =="site-packages"
]
report_paths(lambda: site_packages, "sys.path (site-packages)")
fornameinsysconfig.get_path_names():
expr="sysconfig.get_path({0!r})".format(name)
report_paths(expr)
report_paths("os.__file__")
report_paths("threading.__file__")
report_paths("debugpy.__file__")
report("\n")
importlib_metadata=Nonetry:
importimportlib_metadataexceptImportError: # pragma: no covertry:
fromimportlibimportmetadataasimportlib_metadataexceptImportError:
passifimportlib_metadataisNone: # pragma: no coverreport("Cannot enumerate installed packages - missing importlib_metadata.")
else:
report("Installed packages:\n")
try:
forpkginimportlib_metadata.distributions():
report(" {0}=={1}\n", pkg.name, pkg.version)
exceptException: # pragma: no coverswallow_exception(
"Error while enumerating installed packages.", level="info"
)
return"".join(result).rstrip("\n")
print(get_environment_description("Environment description:"))
That code is identical to what debugpy is running and I get no such exception. The eval is failing for you for some reason.
Activity
rchiodo commentedon Jan 9, 2026
Something is changing 'eval' to not work. This code works fine for me. You can try sticking this in the file you're debugging and see what happens:
That code is identical to what debugpy is running and I get no such exception. The
evalis failing for you for some reason.Charron-Lin commentedon Jan 15, 2026
I installed Python 3.10.11, and debugging also reports this error. It started recently.
Have you solved this problem?