[Python-ideas] Better error messages for missing optional stdlib packages
tjreedy at udel.edu
Sun Oct 7 18:29:19 EDT 2018
On 10/3/2018 4:29 PM, Marcus Harnisch wrote:
> When trying to import lzma on one of my machines, I was suprised to get
> a normal import error like for any other module.
What was the traceback and message? Did you get an import error for one
of the three imports in lzma.py. I don't know why you would expect
anything else. Any import in any stdlib module can potential fail if
the file is buggy, corrupted, or missing.
> 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
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.
> 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.
ImportError messages and the documented status versus actual status of a
module are two different issues. Let's keep them separate.
Terry Jan Reedy
More information about the Python-ideas