From c4156f62bdfd6a274e9ca097d6069e3861e36902 Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Sun, 27 Oct 2024 14:42:19 +0700 Subject: [PATCH 1/5] gh-125873: Improve error message when `PYTHONHOME` is invalid --- .../2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst | 1 + Python/codecs.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst new file mode 100644 index 00000000000000..1c0644b93bb968 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst @@ -0,0 +1 @@ +Improved error message when ``PYTHONHOME`` is invalid. diff --git a/Python/codecs.c b/Python/codecs.c index 2cb3875db35058..91799cf22434fa 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -1526,7 +1526,7 @@ _PyCodec_InitRegistry(PyInterpreterState *interp) // search functions, so this is done after everything else is initialized. PyObject *mod = PyImport_ImportModule("encodings"); if (mod == NULL) { - return PyStatus_Error("Failed to import encodings module"); + return PyStatus_Error("Failed to import encodings module. Are you sure PYTHONHOME is correct?"); } Py_DECREF(mod); From 20008c2c97127e82009b9231a73acd7981aa61ef Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Tue, 29 Oct 2024 07:22:01 +0700 Subject: [PATCH 2/5] Update error message --- .../2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst | 2 +- Python/codecs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst index 1c0644b93bb968..60ce26c2410586 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst @@ -1 +1 @@ -Improved error message when ``PYTHONHOME`` is invalid. +Improved error message when an environment variable is misonfigured. diff --git a/Python/codecs.c b/Python/codecs.c index 91799cf22434fa..97fde060e073fe 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -1526,7 +1526,7 @@ _PyCodec_InitRegistry(PyInterpreterState *interp) // search functions, so this is done after everything else is initialized. PyObject *mod = PyImport_ImportModule("encodings"); if (mod == NULL) { - return PyStatus_Error("Failed to import encodings module. Are you sure PYTHONHOME is correct?"); + return PyStatus_Error("Failed to import encodings module. Your environment probably has misconfigured variables!"); } Py_DECREF(mod); From c1b0264becfe8dc320c33c6b0c4b025dd2e5f17c Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Tue, 29 Oct 2024 07:23:01 +0700 Subject: [PATCH 3/5] fix typo --- .../2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst index 60ce26c2410586..fc4818781ee132 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-27-22-23-57.gh-issue-125873.BG97KU.rst @@ -1 +1 @@ -Improved error message when an environment variable is misonfigured. +Improved error message when an environment variable is misconfigured. From 8392891e3dd0430cccb43da3962ae182280350e6 Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Tue, 29 Oct 2024 13:10:15 +0700 Subject: [PATCH 4/5] Add reference to --help-env --- Python/codecs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/codecs.c b/Python/codecs.c index 97fde060e073fe..501a6567893d89 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -1526,7 +1526,7 @@ _PyCodec_InitRegistry(PyInterpreterState *interp) // search functions, so this is done after everything else is initialized. PyObject *mod = PyImport_ImportModule("encodings"); if (mod == NULL) { - return PyStatus_Error("Failed to import encodings module. Your environment probably has misconfigured variables!"); + return PyStatus_Error("Failed to import encodings module. Your environment probably has misconfigured variables! Please refer to `--help-env`"); } Py_DECREF(mod); From 90ff56a356c78ea923277be60ec2b6292819105d Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Tue, 29 Oct 2024 15:52:39 +0700 Subject: [PATCH 5/5] Mention PYTHONHOME implicitly and styling --- Python/codecs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/codecs.c b/Python/codecs.c index 501a6567893d89..1f30c5e8e21707 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -1526,7 +1526,9 @@ _PyCodec_InitRegistry(PyInterpreterState *interp) // search functions, so this is done after everything else is initialized. PyObject *mod = PyImport_ImportModule("encodings"); if (mod == NULL) { - return PyStatus_Error("Failed to import encodings module. Your environment probably has misconfigured variables! Please refer to `--help-env`"); + return PyStatus_Error("Failed to import encodings module. " + "Your environment probably has misconfigured variables! " + "Please check PYTHONHOME otherwise refer to `--help-env`"); } Py_DECREF(mod);