Better error messages for missing optional stdlib packages

Hi all When trying to import lzma on one of my machines, I was suprised to get a normal import error like for any other module. According to the docs lzma has been part of stdlib since 3.3. Further digging revealed that the error is due to the fact that xz wasn't compiled in when building Python. Since I suspect that there are other optional stdlib modules, this made me think whether the message in those cases should look a little more polished. Perhaps installing a stub module that prints some informative text before raising the relevant exception or similar. Also, maybe add a little note in the docs, stating that despite being part of stdlib this module might not be available on all systems. Thanks, Marcus

On Wed, Oct 03, 2018 at 10:29:45PM +0200, Marcus Harnisch wrote:
This sounds to me like something that the various Python distributors could do, e.g. Activestate, the Linux distros, etc. Especially since they're the ones compiling Python, they can control whether or not XY is supplied or not.
Also, maybe add a little note in the docs, stating that despite being part of stdlib this module might not be available on all systems.
That should be uncontroversial. Raise an issue on the bug tracker for that, or a patch on Github. -- Steve

On Thu, 4 Oct 2018 08:32:55 +1000 Steven D'Aprano <steve@pearwood.info> wrote:
I don't know. Realistically, any decent distributor of Python should include those optional modules, and I don't remember encountering a Python that doesn't has them. Adding a note saying otherwise in the docs may pointlessly scare users away. Regards Antoine.

On 10/3/2018 4:29 PM, Marcus Harnisch wrote: the file is buggy, corrupted, or missing.
Perhaps this is a buggy build. Where did you get it from? Have you complained to the distributor? lzma is documented as wrapping liblzma and supporting .xz files. If 'xz' is a separate library, then perhaps lzma should tolerate it missing.
Since I suspect that there are other optional stdlib modules,
I agree that modules that are necessarily optional should be documented as such, and as I mentioned on https://bugs.python.org/issue34895, many are so documented. In the absence of such documentation, I would considered it to be not optional except as some distributor decides to omit it. But then it is the responsibility of the distributor to document the omission.
Also, maybe add a little note in the docs, stating that despite being part of stdlib this module might not be available on all systems.
ImportError messages and the documented status versus actual status of a module are two different issues. Let's keep them separate. -- Terry Jan Reedy

On 10/08/2018 12:29 AM, Terry Reedy wrote:
$ /usr/bin/python3 Python 3.7.0 (default, Oct 4 2018, 03:21:59) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.
$ grep -F missing.append setup.py missing.append('spwd') missing.append('readline') missing.append('_ssl') missing.append('_hashlib') missing.append('_sqlite3') missing.append('_dbm') missing.append('_gdbm') missing.append('nis') missing.append('_curses') missing.append('_curses_panel') missing.append('zlib') missing.append('zlib') missing.append('zlib') missing.append('_bz2') missing.append('_lzma') missing.append('_elementtree') missing.append('ossaudiodev') missing.append('_tkinter') missing.append('_uuid')
All I am asking is that unsuspecting users not be left in the dark when it comes to debugging unexpected import errors. I believe a missing stdlib module qualifies for “unexpected”. This could happen in form of documentation or by means of an import error handler that prints some helpful message in case that a stdlib module couldn't be found. Regards, Marcus

On Wed, Oct 03, 2018 at 10:29:45PM +0200, Marcus Harnisch wrote:
This sounds to me like something that the various Python distributors could do, e.g. Activestate, the Linux distros, etc. Especially since they're the ones compiling Python, they can control whether or not XY is supplied or not.
Also, maybe add a little note in the docs, stating that despite being part of stdlib this module might not be available on all systems.
That should be uncontroversial. Raise an issue on the bug tracker for that, or a patch on Github. -- Steve

On Thu, 4 Oct 2018 08:32:55 +1000 Steven D'Aprano <steve@pearwood.info> wrote:
I don't know. Realistically, any decent distributor of Python should include those optional modules, and I don't remember encountering a Python that doesn't has them. Adding a note saying otherwise in the docs may pointlessly scare users away. Regards Antoine.

On 10/3/2018 4:29 PM, Marcus Harnisch wrote: the file is buggy, corrupted, or missing.
Perhaps this is a buggy build. Where did you get it from? Have you complained to the distributor? lzma is documented as wrapping liblzma and supporting .xz files. If 'xz' is a separate library, then perhaps lzma should tolerate it missing.
Since I suspect that there are other optional stdlib modules,
I agree that modules that are necessarily optional should be documented as such, and as I mentioned on https://bugs.python.org/issue34895, many are so documented. In the absence of such documentation, I would considered it to be not optional except as some distributor decides to omit it. But then it is the responsibility of the distributor to document the omission.
Also, maybe add a little note in the docs, stating that despite being part of stdlib this module might not be available on all systems.
ImportError messages and the documented status versus actual status of a module are two different issues. Let's keep them separate. -- Terry Jan Reedy

On 10/08/2018 12:29 AM, Terry Reedy wrote:
$ /usr/bin/python3 Python 3.7.0 (default, Oct 4 2018, 03:21:59) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.
$ grep -F missing.append setup.py missing.append('spwd') missing.append('readline') missing.append('_ssl') missing.append('_hashlib') missing.append('_sqlite3') missing.append('_dbm') missing.append('_gdbm') missing.append('nis') missing.append('_curses') missing.append('_curses_panel') missing.append('zlib') missing.append('zlib') missing.append('zlib') missing.append('_bz2') missing.append('_lzma') missing.append('_elementtree') missing.append('ossaudiodev') missing.append('_tkinter') missing.append('_uuid')
All I am asking is that unsuspecting users not be left in the dark when it comes to debugging unexpected import errors. I believe a missing stdlib module qualifies for “unexpected”. This could happen in form of documentation or by means of an import error handler that prints some helpful message in case that a stdlib module couldn't be found. Regards, Marcus
participants (6)
-
Anders Hovmöller
-
Antoine Pitrou
-
Marcus Harnisch
-
Neil Girdhar
-
Steven D'Aprano
-
Terry Reedy