Search code examples
pythonwordnetlzmapyscriptpyodide

PyScript ModuleNotFoundError: No module named '_lzma'


Piggybacking off a previous question that I submitted: Using WordNet with PyScript

I'm trying to install WordNet in PyScript using

await micropip.install('https://files.pythonhosted.org/packages/ce/f1/53b07100f5c3d41fd33fc78ebb9e99d736b0460ced8acff94840311ffc60/wn-0.9.1-py3-none-any.whl')

This gives me the error:

JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception File "/lib/python3.10/asyncio/tasks.py", line 232, in __step result = coro.send(None) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 500, in eval_code_async await CodeRunner( File "/lib/python3.10/site-packages/_pyodide/_base.py", line 353, in run_async await coroutine File "", line 14, in File "/lib/python3.10/site-packages/wn/init.py", line 47, in from wn._add import add, remove File "/lib/python3.10/site-packages/wn/_add.py", line 21, in from wn.project import iterpackages File "/lib/python3.10/site-packages/wn/project.py", line 12, in import lzma File "/lib/python3.10/lzma.py", line 27, in from _lzma import * ModuleNotFoundError: No module named '_lzma' )

Looking at some questions related to the "ModuleNotFoundError: No module named '_lzma'", the idea generally seems to be that it is an issue related to the Python installation. However, I am not sure how to go about resolving this within PyScript.

Any clues on what I did wrong/what I should do?


Solution

  • lzma is currently not included in Pyodide Python builds to reduce download size. Lzma remains an optional module, so the package should not fail if it's missing. You can report this issue to https://github.com/goodmami/wn

    Meanwhile a temporary workaround is to remove that lzma import in wn, create a new python wheel with,

    pip install build
    python -m build
    

    and install that with micropip by providing the URL.

    It's possible that we may add lzma module in Pyodide the future pyodide#2937