Skip to content

Commit 58eb3f2

Browse files
committed
gh-151253: Dump the path config if "import encodings" fails
If "import encodings" fails at Python startup, dump the Python path configuration to help users debugging their configuration. The encodings module is the first module imported during Python startup.
1 parent 8c0e251 commit 58eb3f2

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
If ``import encodings`` (first import) fails at Python startup, dump the
2+
Python path configuration to help users debugging their configuration. Patch
3+
by Victor Stinner.

Python/codecs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Copyright (c) Corporation for National Research Initiatives.
1111
#include "Python.h"
1212
#include "pycore_call.h" // _PyObject_CallNoArgs()
1313
#include "pycore_codecs.h" // export _PyCodec_LookupTextEncoding()
14+
#include "pycore_initconfig.h" // _Py_DumpPathConfig()
1415
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
1516
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
1617
#include "pycore_pystate.h" // _PyInterpreterState_GET()
@@ -1686,6 +1687,8 @@ _PyCodec_InitRegistry(PyInterpreterState *interp)
16861687
// search functions, so this is done after everything else is initialized.
16871688
PyObject *mod = PyImport_ImportModule("encodings");
16881689
if (mod == NULL) {
1690+
PyThreadState *tstate = _PyThreadState_GET();
1691+
_Py_DumpPathConfig(tstate);
16891692
return PyStatus_Error("Failed to import encodings module");
16901693
}
16911694
Py_DECREF(mod);

0 commit comments

Comments
 (0)