This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Change the exception message raised when _curses is not found.
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, eric.snow, ncoghlan, ned.deily, ronaldoussoren, serhiy.storchaka, shreyanavigyan
Priority: normal Keywords:

Created on 2021-04-04 15:17 by shreyanavigyan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (14)
msg390195 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-04-04 15:17
When importing the curses module, be it on Windows or Darwin or UNIX-based OS or any other platform, if the _curses module is not found then just a ModuleNotFoundError is raised. But this error is not very informational in case of _curses module. Since the curses module is packaged with the Python interpreter itself at first it may seem, to beginners especially, that the Python interpreter was not installed correctly and then they would go searching for an answer for about 4-5 days. 

We know that curses library is not installed on windows by default and may or may not be present on other operating systems. Most UNIX system have ncurses or other curses library installed by default. 

Python errors have a reputation of being very informational. I would like to submit a PR to modify the curses module a little bit by declaring a BaseException class and raising that Exception with the message "_curses module not found. Make sure a curses library is installed" or some kind of message like that.

But before I do that I would like to take advice from experienced developers about somethings. Is this change in the exception, raised when _curses module is not found, acceptable by the Python Community? If it is then should a draft PEP be submitted or should a PR be directly submitted to python/cpython?
msg390226 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-04-05 07:38
ModuleNotFoundError is the correct exception. Its purpose is to be raised for missed modules.

I do not know about macOS, but the curses module is not supported on Windows, so it is expected to get ModuleNotFoundError.

Some distributions can provide some stdlib modules (like tkinter, or distutils, or tests) as separate packages.
msg390227 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-04-05 07:53
The curses module is not supported on all platforms is very clear. But beginners may seem to think that their python was not installed properly and then they would go around looking for answer. To make it clear I was thinking of how about changing just the message and if required then the type (maybe CursesNotFoundError exception class derived from ModuleNotFoundError class) so that the error message became a little bit informational. The message could be like "_curses library not installed. Install a supported curses library to use the curses module" or something like that? 

The exception right now looks like this :-

ModuleNotFoundError: No module named '_curses'

What about something like this :-

CursesNotFoundError: "_curses library not installed. Install a supported curses library to use the curses module."

N.B.: The curses library still can be used on Windows by using the UniCurses library or Christoph Gohlke's unofficial curses or some other third party library.
msg390230 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-04-05 09:57
What about only changing the error message to make it a little bit informational? Something like :-

ModuleNotFoundError: _curses library not found. Install a supported _curses library to use the curses module.
msg390238 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-04-05 14:37
> ModuleNotFoundError: _curses library not found. Install a supported _curses library to use the curses module.

Is installing _curses possible, on any supported platform? Or would a better message say that curses is not supported on this platform?
msg390239 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-04-05 15:07
> Is installing _curses possible, on any supported platform? Or would a better message say that curses is not supported on this platform?

No _curses can't be installed on any platform. I don't know about macOS but _curses can be installed on Windows and Linux (and presumably any UNIX-based OS). On Windows, Christoph Gohlke's unofficial curses, windows-curses and lot's of libraries allows us to use _curses library. Though I think curses can't be used directly on Windows cmd or powershell. Terminals provided by the Mingw-w64 project, the Cygwin project, etc., most presumably support curses library. WSL terminal also seem to support curses (ncurses). 

So what about a error message like this :-

ModuleNotFoundError: _curses library not found. Install a supported _curses library to use the curses module or migrate to a supported platform.

N.B.: UniCurses library may work with Windows cmd or powershell because it wraps up the PDCurses library on Windows which was developed specifically to work with Windows. Though UniCurses actually can't be used with the Python built-in module curses. We have to specifically import 'unicurses' to use it.
msg390240 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-04-05 15:14
While I wouldn't object to tweaking the message associated with the exception, I'm not sure it's necessary. Googling "curses modulenotfound" gives a number of hits that have good information about the issue. Is there really a practical problem that's being solved here?

"migrate to a supported platform" is almost never practical advice. If we make any change, I'd just say it's not supported on this platform. Or maybe "you may be running on platform that is not supported by curses".
msg390241 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-04-05 15:18
> "migrate to a supported platform" is almost never practical advice. If we make any change, I'd just say it's not supported on this platform. Or maybe "you may be running on platform that is not supported by curses".

Ok...So what about a message like this :-
ModuleNotFoundError: _curses library not found. Install a supported _curses library to use the curses module (The _curses library may not be supported on your platform).
msg390244 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-04-05 16:49
Is this confirmed? If yes then I'll open a PR on https://github.com/python/cpython
msg390248 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-04-05 18:52
Is this issue ready for a PR?
msg390255 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-04-05 20:02
"Install a supported _curses library"

That's not correct advice. _curses is the name of the support module written in C in the Python Standard Library. If it is not available to import in an installation, it's most likely because the build of the module failed because the third-party libraries that implement curses functionality was not installed or not found during the build. How you install the third-party curses library varies greatly by platform or distribution. Some distributions have multiple variants of curses packages, ones with just libraries and others ("-dev" packages) that include header files necessary for Python to build its _curses module.  The Dev Guide has some information on dependencies in general and the details for _curses are in the code in setup.py.  It's also possible that the distributor has broken Python curses support out into a separate package. So it's not easy to provide a message with a useful specific suggestion; there are just too many cases.
msg390267 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-04-05 23:58
I agree with Ned. This is why I'm not sure it’s worth changing the message: googling gives good information, and the exact thing to do in order resolve this (if it’s even possible) is dependent on a number of factors that the code raising the exception can’t know.
msg390275 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-04-06 04:54
Yeah...I agree. Therefore this issue is resolved and I will close this issue now. Thanks everyone for the advice.

With Regards
msg390276 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-04-06 04:56
@shreyanavigyan: Thank you for your efforts to improve Python!
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87894
2021-04-06 04:56:58eric.smithsetresolution: wont fix
messages: + msg390276
2021-04-06 04:54:24shreyanavigyansetstatus: open -> closed
stage: resolved
2021-04-06 04:54:03shreyanavigyansetmessages: + msg390275
2021-04-05 23:58:22eric.smithsetmessages: + msg390267
2021-04-05 20:02:01ned.deilysetmessages: + msg390255
2021-04-05 18:52:51shreyanavigyansetmessages: + msg390248
2021-04-05 17:13:36shreyanavigyansettitle: Change the exception type and message raised when _curses is not found. -> Change the exception message raised when _curses is not found.
2021-04-05 16:49:12shreyanavigyansetmessages: + msg390244
2021-04-05 15:58:00brett.cannonsetnosy: - brett.cannon
2021-04-05 15:18:31shreyanavigyansetmessages: + msg390241
2021-04-05 15:14:08eric.smithsetmessages: + msg390240
2021-04-05 15:07:08shreyanavigyansetmessages: + msg390239
2021-04-05 14:37:34eric.smithsetnosy: + eric.smith
messages: + msg390238
2021-04-05 09:57:07shreyanavigyansetmessages: + msg390230
2021-04-05 07:53:29shreyanavigyansetmessages: + msg390227
2021-04-05 07:38:43serhiy.storchakasetnosy: + serhiy.storchaka, ned.deily, eric.snow, brett.cannon, ncoghlan, ronaldoussoren
messages: + msg390226
2021-04-04 15:17:03shreyanavigyancreate