Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 61411) +++ Python/pythonrun.c (working copy) @@ -733,6 +733,7 @@ PyObject *m; PyObject *std = NULL; int status = 0, fd; + PyObject * encoding_attr; /* Hack to avoid a nasty recursion issue when Python is invoked in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ @@ -823,6 +824,19 @@ goto error; } } /* if (fd < 0) */ + + /* Same as hack above, pre-import stderr's codec to avoid recursion + when import.c tries to write to stderr in verbose mode. */ + encoding_attr = PyObject_GetAttrString(std, "encoding"); + if (encoding_attr != NULL) { + const char * encoding; + encoding = PyUnicode_AsString(encoding_attr); + if (encoding != NULL) { + _PyCodec_Lookup(encoding); + } + } + PyErr_Clear(); /* Not a fatal error if codec isn't available */ + PySys_SetObject("__stderr__", std); PySys_SetObject("stderr", std); Py_DECREF(std);