[Python-ideas] Better error messages for missing optional stdlib packages
mh-python at online.de
Mon Oct 8 12:49:30 EDT 2018
On 10/08/2018 12:29 AM, Terry Reedy wrote:
> 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.
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.
>>> import lzma
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/lzma.py", line 27, in <module>
ModuleNotFoundError: No module named '_lzma'
> > 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.
This, I reckon, depends on the perspective and the definition of
“buggy”. If the build process finishes without error, can we assume that
the build is not buggy? If we make claims along the lines of “nobody in
their right mind would build Python without lzma” it would only be fair
to break the build if liblzma can't be detected.
Unless I missed anything it doesn't happen until after the build has
finished successfully, that a message is printed which lists the modules
which couldn't be detected by setup.py.
Here is a list of modules, which I believe are affected:
$ grep -F missing.append setup.py
> Have you complained to the distributor?
After finding the root cause of the missing import I did file a request
for including lzma in future releases of the distribution.
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas