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.

$ /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.
>>> 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 Python.

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
            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')

  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.

Regards,
Marcus