[Python-ideas] Better error messages for missing optional stdlib packages

Steven D'Aprano steve at pearwood.info
Wed Oct 3 18:32:55 EDT 2018


On Wed, Oct 03, 2018 at 10:29:45PM +0200, Marcus Harnisch wrote:
> 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.

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


More information about the Python-ideas mailing list